开发者

Git merge commits between branches

I've got two branches. Lets call them A & B for now. I want to selectively copy something like 20 commits from A to B. Is there any efficient way to do this?

I know I can git cherry-pick commits one at a time but can I do 20 all at once? This is assuming the 20 commits aren't together a开发者_JAVA技巧nd there are commits in between them that I do not want copied over.

Example. Branch A commits

4->5->6->7

Branch B

1->2->3->8

I want to copy 4,5,7 over to B.


I would rather rebase --interactive A onto B, because cherry-picking introduce duplicate commits, which is generally not a good idea.
See "Git cherry pick and datamodel integrity".

That being said, you can specify sets of commits and multiple commits in a git cherry-pick command. Separate each commits by a space, and look at how specifying said commits in gitrevision.


You can pass as many commits as you want to git cherry-pick

$ git checkout B
$ git cherry-pick A~3 A~2 A

Will do what you describe in your example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜