我想将另一个分支中存在的文件的不同版本加载到我当前的分支中。
git help checkout
说:
DESCRIPTION
Updates files in the working tree to match the version in the index or
the specified tree. If no paths are given, git checkout will also
update HEAD to set the specified branch as the current branch.
有没有办法检查所有这些文件,但不更新 HEAD?
通过提供当前路径 .
结帐:
git checkout other-branch-name -- .
此操作类似于switching HEAD to another branch without checking out files,但只是从“其他方向”。
正如@김민준 所提到的,这会覆盖任何未提交的更改。如果需要,请记住先将它们存储或提交到某个地方。
与 @Kache's answer 类似,但使用较新的 git restore
命令(需要 Git 2.23 或更高版本):
git restore --source=<other-branch/tag/commit> <pathspec>
# or
git restore -s <other-branch/tag/commit> <pathspec>
# example: to load all files from branch "other"
git restore -s other .
引入这个新命令是为了将“签出分支”和“签出文件”从单个 git checkout
命令中分离出来。阅读更多:What is the git restore
command。
-- .
有点难找,谢谢!--
作为左侧命令和右侧文件 glob 之间的分隔符。git checkout <other-branch-name> -- C:\path\to\changes\*