Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge only the diff between two branches

Tags:

git

Say I have branchA with the latest features and then I have the branchBwhich has the hotfixes not yet sync into branchA.

What I want to do is merged all hotfixes into that latest features (branchA) but only the diff. I saw that git log branchA..branchB actually shows the commits in branchB not yet existing in branchA. Unfortunately I don't know the command how to merged the branchB diff commits into branchA

like image 271
david Avatar asked Jul 30 '18 16:07

david


People also ask

How do I compare the differences between two branches in github?

On the Github, go to the Source view of your project. You will see a link named 'Branch List'. Once the page opens you can see a list of all the remote branches. Hit on the Compare button in front of any of the available branches to see the difference between two branches.

Does git merge change both branches?

No, merging does only affect one branch.


2 Answers

You're very close. You can do it as a patch:

git diff branchA..branchB > mypatch.patch

Then apply the patch to the desired branch:

git apply mypatch.patch
like image 95
unigeek Avatar answered Oct 20 '22 03:10

unigeek


If you want to apply changes from branch X to current branch:

git diff ..X | git apply -

This is simply a shorter version of the accepted answer.

like image 7
Andrey Portnoy Avatar answered Oct 20 '22 04:10

Andrey Portnoy