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
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With