Manish Burman
Manish Burman

Reputation: 3079

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 and 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.

Upvotes: 3

Views: 3027

Answers (2)

VonC
VonC

Reputation: 1323095

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.

Upvotes: 3

Mat
Mat

Reputation: 206659

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.

Upvotes: 2

Related Questions