Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge hot fix on branch to master [duplicate]

Tags:

git

If I start with a structure like follows on my remote:

A-B-C-D-F-G  master
   \
    E-H-I  branch

And I clone branch and make change 'J' (& commit and push to remote branch) how can I merge 'J' to master without bringing down 'H' and 'I'? Can it be done just by pushing change 'J' or do I need to switch to a local repo tracking master and merge the local 'J' change and push that to master?

A-B-C-D-F-G-J  master
   \       
    E-H-I-J  branch
like image 905
BenG Avatar asked Oct 17 '25 02:10

BenG


2 Answers

To make a history that reflects reality and so save yourself potential trouble downstream,

git checkout -b Jbranch B
git cherry-pick J
git checkout -B branch I
git merge Jbranch
git checkout -B master G
git merge Jbranch
git branch -d Jbranch

Producing

A..B..C..D..F..G..J''  master
   |             /
   |\........J'.+
   |             \ 
    \....E..H..I..J    branch

The 'J' commit's tree in the old and new 'branch' tip will be identical, just with the explicit history this time.

like image 71
jthill Avatar answered Oct 18 '25 20:10

jthill


You can cherry-pick the change J. Cherry-picking only copies a particular commit to a branch.

$ git checkout master
$ git cherry-pick J

Note that commit J will now be duplicated (it'll exist on each branch).

like image 24
mipadi Avatar answered Oct 18 '25 20:10

mipadi