我如何从一个git回购签出一个文件?
当前回答
Git checkout branch_or_version——path/file
示例:git checkout HEAD——main.c
其他回答
最小的指南
Git checkout——<filename>
裁判:https://git-scm.com/docs/git-checkout
Dup:在Git中撤销一个文件的工作副本修改?
非常简单:
git checkout from-branch-name -- path/to/the/file/you/want
这将不会签出from-branch-name分支。您将停留在您所在的分支上,并且只有该文件将从指定的分支签出。
下面是git-checkout手册的相关部分
git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
When <paths> or --patch are given, git checkout does not switch
branches. It updates the named paths in the working tree from the
index file or from a named <tree-ish> (most often a commit). In
this case, the -b and --track options are meaningless and giving
either of them results in an error. The <tree-ish> argument can be
used to specify a specific tree-ish (i.e. commit, tag or tree) to
update the index for the given paths before updating the working
tree.
向Ariejan de Vroom致敬,他在这篇博客文章中教会了我这些。
是的,你可以通过这个命令下载一个特定的文件
wget -o <DesiredFileName> <Git FilePath>\?token\=<personalGitToken>
例子
wget -o javascript-test-automation.md https://github.com/akashgupta03/awesome-test-automation/blob/master/javascript-test-automation.md\?token\=<githubPersonalTone>
如果您编辑了文件的本地版本,并希望恢复到中央服务器上维护的原始版本,可以使用Git扩展轻松实现。
最初文件将被标记为提交,因为它已被修改 在文件树菜单中选择(双击)该文件 列出了单个文件的修订树。 选择树的顶部/HEAD,然后右键单击save as 保存该文件以覆盖修改后的文件本地版本 文件现在有正确的版本,将不再被标记为提交!
简单!
我添加这个答案作为做正式签出或一些类似的本地操作的替代方案。假设您可以访问Git提供程序的web界面,您可能能够在给定的提交时直接查看任何文件。例如,在GitHub上,你可以使用这样的东西:
https://github.com/hubotio/hubot/blob/ed25584f/src/adapter.coffee
这里ed25584f是感兴趣的提交的SHA-1散列的前8个字符,后面是源文件的路径。
类似的,在Bitbucket上我们可以尝试:
https://bitbucket.org/cofarrell/stash-browse-code-plugin/src/06befe08
在本例中,我们将提交散列放在源URL的末尾。
推荐文章
- git可以自动在空格和制表符之间切换吗?
- Git暂存文件列表
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- Python列表目录,子目录和文件
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔
- 我如何知道我在S3桶中存储了多少对象?
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时
- git reflog和log有什么区别?
- git推挂在Total line之后