从GIT远程分支获取特定文件

Mar*_*ore 10 git

是否可以从远程存储库中提取但只选择性地从我感兴趣的那个遥控器中获取文件?我不想简单地拉下整个分支.

谢谢.

Chr*_*her 17

"远程分支"只不过是提交指针和附属包数据.只是git fetch <remote>如果你想查看遥控器和本地文件之间的差异,你可以这样做:

git diff <local_branch> <remote>/<remote_branch> -- <file>
Run Code Online (Sandbox Code Playgroud)

例如,在许多情况下这将是git diff master origin/master -- <file>.您还可以看到提交差异git log:

git log <local_branch>..<remote>/<remote_branch> -- <file>
Run Code Online (Sandbox Code Playgroud)

所以... git log master..origin/master -- <file>

最后,如果您只想从远程检出特定版本的文件(这可能不太理想;将远程分支与git merge <remote>/<remote_branch>or 合并要好得多git pull),请使用:

git checkout <remote>/<remote_branch> -- <file>
Run Code Online (Sandbox Code Playgroud)