时间:2010-07-26 11:44:59

标签: git git-checkout

7 个答案:

答案 0 :(得分:760)

可以(在已部署的存储库中)

git fetch
git checkout origin/master -- path/to/file

fetch将下载所有最近的更改,但不会将其放入当前检出的代码(工作区域)。

结帐将使用下载的更改(origin/master)中的特定文件更新工作树。

至少这对我来说对于那些小小的错字修复,在创建分支等只是为了改变文件中的一个单词感觉很奇怪。

答案 1 :(得分:18)

git archive --format=zip --remote=ssh://<user>@<host>/repos/<repo name> <tag or HEAD> <filename> > <output file name>.zip

答案 2 :(得分:11)

以下代码对我有用:

     git fetch
     git checkout <branch from which file needs to be fetched> <filepath> 

答案 3 :(得分:6)

答案 4 :(得分:6)

使用Git 2.23(2019年8月)和新的(仍处于试验阶段)命令 git restore (在“ How to reset all files from working directory but not from staging area?”中看到)将是:

git fetch
git restore -s origin/master -- path/to/file

这个想法是:git restore只处理文件,而不像git checkout处理文件分支。
请参阅“ Confused by git checkout”: git switch 的出现位置)

答案 5 :(得分:2)

或者你正在使用的分支上的git stash(如果你有更改),checkout master,拉取最新的更改,将该文件抓取到你的桌面(或整个应用程序)。检查你所在的分行。 Git stash应用回你所处的状态,然后手动修复更改或拖动它替换文件。

这种方式并不太酷,但如果你们不能解决任何问题,那么def就可以了。

答案 6 :(得分:-4)

我想我已经找到了一个简单的黑客。

删除本地存储库中的文件(要从远程服务器中的最新提交更新的文件)

然后执行git pull

因为文件已删除,所以不存在冲突