我在一个站点上工作,该站点的服务器运行 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/