huggie
huggie

Reputation: 18247

Git merge changes between two specific commits from another branch

I have versions from A to E. Two branch heads, Branch1 and Branch2.

E <- Branch2
|
D
|
C
|
B
|
A <- Branch1

Now I want to apply the difference between say C and D, to Branch1, such that the difference between A and A1, is exactly the same between C and D.

E <- Branch2
|
D
|
C
|
B A1 <- Branch1
| /
A 

Two questions.

  1. How do I do this? Do I make a patch file? Or is there a way to make this work in Git so that Git knows it's the same difference?
  2. Actually I did try git diff C D > patch.diff to make a patch and then git apply patch.diff to apply and somehow I don't see the difference in it.

Upvotes: 1

Views: 50

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522626

I believe you can just cherry-pick commit D from Branch2 onto your Branch1:

git checkout Branch1
git cherry-pick <SHA-1 for commit D>

The reason this should work is that commit D is essentially represents a diff between commits C and D. You wish to apply this change set on a different commit, in this case commit A on Branch1.

Upvotes: 2

Related Questions