简体   繁体   English

如何使用git将另一个分支中的文件签出到当前分支的新文件中?

[英]How can I check out a file from another branch into a new file in the current branch with git?

Let's say that I have a file core.clj in branch master at HEAD which is distinct from core.clj in branch other at HEAD, and that I am currently in branch other. 假设我在HEAD的分支主机中有一个文件core.clj,它与HEAD中的分支机构中的core.clj不同,而且我目前在分支机构中。 I would like to checkout master's core.clj into the current branch with some other file name, say tmp.clj, for easy comparison. 我想将master的core.clj用一些其他文件名(例如tmp.clj)检入当前分支,以便于比较。

How can I do this? 我怎样才能做到这一点?

You can use git show master:core.clj to show the file. 您可以使用git show master:core.clj来显示该文件。 Redirect it to a new file ( git show ... > temp.clj to save it for further processing. 将其重定向到一个新文件( git show ... > temp.clj以保存它以供进一步处理。

You don't need to; 你不需要; git diff will do exactly what you need to do. git diff将完全按照您的需要做。 git diff master otherbranch core.clj is a basic use of the command, and if you need more help, man git-diff can explain more to you. git diff master otherbranch core.clj是命令的基本用法,如果你需要更多的帮助, man git-diff可以向你解释更多。

这非常简单:

 git checkout master -- core.clj

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在git中将文件历史记录从一个分支合并到另一个分支? - How can I merge a file history from a branch to another in git? 如何在不使用git本身的情况下从代码中查找当前的Git分支名称? .git / HEAD文件? - How can I find out the current Git branch name from code, without using git itself? .git/HEAD file? 如何将所有文件和文件夹从一个分支替换/复制到GIT中的另一个现有分支 - How Can I replace/copy all file and folder from one branch to another existing branch in GIT 如何将一个分支中的特定文件合并到Git中的另一个分支中 - How can I merge a specific file from one branch into another branch in Git 我可以将来自 Git 分支的文件与 Sublime 中另一个 Git 分支的相同文件进行比较吗 - Can I compare a file from a Git branch with the same file of another Git branch in Sublime 如何使用先前更改、当前更改和来自另一个分支的新文件创建新分支? - How to create new branch with with previous changes, current changes and new file from another branch? 在git中通过bash检出另一个分支中的所有冲突文件 - check out all conflicted file in another branch via bash in git 如何使用 git 从另一个分支打印文件? - How do I print a file from another branch with git? 如何检查文件在另一个分支上是否有前进进度? - How can I check if a file has forward progress on another branch? 如何在git分支中“隔离”文件 - How can I “Isolate” file in a git branch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM