Git:如何从 Git 中的服务器存储库中提取单个文件?

标签 git git-merge git-pull git-fetch

我在一个站点上工作,该站点的服务器运行 Git。我正在使用 Git 进行部署(不是 GitHub)。这是在我参与之前使用 hook method 设置的,我提到了this question并输入下面的命令,但没有用。

如何从服务器中提取单个文件?例如,如果我想更新我的本地文件 index.php? git pull index.php?

最佳答案

简答

可以这样做(在已部署的存储库中):

git fetch --all
// git fetch will download all the recent changes, but it will not put it in your current checked out code (working area).

其次是:

git checkout origin/master -- path/to/file
// git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master).

完整示例

$ cd /project/directory

$ git branch
* develop

检查远程名称

$ git remote -v
origin git@github.com:abc/123.git

确认它是来源

我在分支 develop 上,需要来自分支 main 的文件

我需要的文件是 src/scss/main.scss

git fetch --all
git checkout origin/main -- src/scss/main.scss

关于Git:如何从 Git 中的服务器存储库中提取单个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28375418/

相关文章:

git - 我可以使用 git pull --rebase 而不是 "git stash git pull git stash pop"吗?

git pull --rebase 与 git rebase : what's the danger?

git - 如何阻止 Git 中某些特定类型的文件提交?

windows - Windows批处理文件中的git grep和xargs?

GIT 警告 : too many files skipping inexact rename detection

Git:每次 pull origin master 都会导致与消息 merge

git - merge 后提交 ID 是否保持不变?

git - 撤消 git pull --rebase

git - 我怎样才能 git pull --rebase 但进行所有远程更改?

贡献者页面的 Git 颜色代码