我有BranchA,比BranchB快113次提交。
但我只希望最后10个左右的提交从BranchA合并到BranchB。
有办法做到这一点吗?
我有BranchA,比BranchB快113次提交。
但我只希望最后10个左右的提交从BranchA合并到BranchB。
有办法做到这一点吗?
当前回答
git cherry-pick <commit>命令允许您获得一个提交(来自任何分支),本质上,在您的工作分支中重新设置它。
Pro Git书的第5章比我更好地解释了它,包括图表等。(关于rebase的章节也很值得一读。)
最后,在另一个SO问题中,有一些关于樱桃选择vs合并vs重基的很好的评论。
其他回答
如果BranchA还没有被推到远程,那么你可以使用rebase重新排序提交,然后简单地合并。如果可能的话,最好使用merge而不是rebase,因为它不会创建重复提交。
git checkout BranchA
git rebase -i HEAD~113
... reorder the commits so the 10 you want are first ...
git checkout BranchB
git merge [the 10th commit]
git cherry-pick <commit>命令允许您获得一个提交(来自任何分支),本质上,在您的工作分支中重新设置它。
Pro Git书的第5章比我更好地解释了它,包括图表等。(关于rebase的章节也很值得一读。)
最后,在另一个SO问题中,有一些关于樱桃选择vs合并vs重基的很好的评论。
来源:https://git-scm.com/book/en/v2/Distributed-Git-Maintaining-a-Project Integrating-Contributed-Work
The other way to move introduced work from one branch to another is to cherry-pick it. A cherry-pick in Git is like a rebase for a single commit. It takes the patch that was introduced in a commit and tries to reapply it on the branch you’re currently on. This is useful if you have a number of commits on a topic branch and you want to integrate only one of them, or if you only have one commit on a topic branch and you’d prefer to cherry-pick it rather than run rebase. For example, suppose you have a project that looks like this:
如果你想把e43a6提交到你的主分支中,你可以运行
$ git cherry-pick e43a6
Finished one cherry-pick.
[master]: created a0a41a9: "More friendly message when locking the index fails."
3 files changed, 17 insertions(+), 3 deletions(-)
这将引入e43a6中引入的相同更改,但您将获得一个新的提交SHA-1值,因为应用的日期不同。现在你的历史是这样的:
现在您可以删除主题分支并删除不想导入的提交。