我有比BranchB
提前113次提交的BranchA
。
但我只希望将BranchA
的最后10个提交合并到BranchB
中。
有没有办法做到这一点?
发布于 2011-06-16 21:16:23
git cherry-pick <commit>
命令允许您接受一次提交(从任何分支),并且本质上是在您的工作分支中对其进行重新基址。
Chapter 5 of the Pro Git book explains it better than I can,有完整的图表等等。(The chapter on Rebasing也是不错的读物。)
最后,还有一些good comments on the cherry-picking vs merging vs rebasing in another SO question。
发布于 2016-11-16 18:04:09
来源:https://git-scm.com/book/en/v2/Distributed-Git-Maintaining-a-Project#Integrating-Contributed-Work
将引入的工作从一个分支转移到另一个分支的另一种方法是精挑细选。Git中的精挑细选就像是一次提交的rebase。它采用在提交中引入的补丁,并尝试在您当前所在的分支上重新应用它。如果你在一个主题分支上有多个提交,并且你只想集成其中的一个,或者如果你在一个主题分支上只有一个提交,而你更喜欢精挑细选而不是运行rebase,这是很有用的。例如,假设您有一个项目,如下所示:
如果您想将提交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中引入的相同更改,但您将获得一个新的commit SHA-1值,因为应用的日期不同。现在你的历史是这样的:
现在,您可以删除主题分支并删除您不想引入的提交。
发布于 2014-02-20 01:59:00
如果BranchA没有被推送到远程,那么您可以使用rebase
对提交进行重新排序,然后简单地使用merge
。在可能的情况下,最好使用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]
https://stackoverflow.com/questions/6372044
复制相似问题