从 GIT 远程分支获取特定文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12040934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get specific files from a GIT remote branch
提问by Martin Blore
Is it possible to pull from a remote repository but only selectively take files from that remote that I'm interested in? I don't want to simply pull down the entire branch.
是否可以从远程存储库中提取文件,但只能有选择地从我感兴趣的那个远程获取文件?我不想简单地拉下整个分支。
Thanks.
谢谢。
回答by Christopher
A "remote branch" is nothing more than a commit pointer and the affiliated pack data. Just git fetch <remote>
and then if you want to view diffs between files on the remote and your local, you can do so with:
“远程分支”只不过是一个提交指针和附属的包数据。只是git fetch <remote>
,然后,如果你想在遥控器上的文件和本地之间查看diff文件,你可以这样做有:
git diff <local_branch> <remote>/<remote_branch> -- <file>
This would in many cases be, for example, git diff master origin/master -- <file>
. You could also see the commit differences with git log
:
例如,在许多情况下,这将是git diff master origin/master -- <file>
. 您还可以通过以下方式查看提交差异git log
:
git log <local_branch>..<remote>/<remote_branch> -- <file>
so... git log master..origin/master -- <file>
所以... git log master..origin/master -- <file>
Finally if you just want to checkout a particular version of a file from the remote (this wouldn't be ideal; much better to merge the remote branch with git merge <remote>/<remote_branch>
or git pull
), use:
最后,如果您只想从远程签出特定版本的文件(这并不理想;将远程分支与git merge <remote>/<remote_branch>
或合并会更好git pull
),请使用:
git checkout <remote>/<remote_branch> -- <file>
回答by manojlds
No you have to fetch the entire branch, but may choose to checkout specific files.
不,您必须获取整个分支,但可以选择检出特定文件。