如何使用 1 个命令从 Git 的另一个分支中挑选最后一个 sha?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20872829/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:31:28  来源:igfitidea点击:

How to cherry-pick the last sha from another branch in Git with 1 command?

gitgit-branchshagit-cherry-pick

提问by FoxyGio

I find myself doing this a lot when cherry-picking a commit from another branch.

在从另一个分支挑选提交时,我发现自己经常这样做。

$ git log -1 another_branch
commit <commit_sha>
// copy <commit_sha>
$ git cherry-pick <commit_sha>

Can I do all of this in one command, if so, what is it?

我可以在一个命令中完成所有这些操作吗?如果可以,它是什么?

回答by pbetkier

Just go with:

只是去:

$ git cherry-pick another_branch

This will cherry-pick the last commit from another_branch.

这将从 another_branch 中挑选最后一个提交。

Branches in git are just references to the last commit in that branch, you can use them instead of commit SHAs in your commands.

git 中的分支只是对该分支中最后一次提交的引用,您可以在命令中使用它们而不是提交 SHA。