Move fix-commit from one branch to another, before merging them

57 views Asked by At

Working on an incomplete feature branch I already committed a Fix for master.

(master)    A-B-C
(feature)        \_D-E-Fix-G-H

How do I get the Fix commit onto master, ...

(master)    A-B-C------Fix'
(feature)        \_D-E-Fix-G-H

... but still being able to merge/rebase my feature branch on master?

(master)    A-B-C-D-E-Fix-G-H

I suppose Fix' should maintain the same SHA of Fix in order to not be seen a total different commit and be merged/rebased smoothly (so cherry-pick, that I usually use, is not helpful here). So maybe it is not possible, but I am curious if there is any way to share some temporary fixes from a branch with another branch, and still be able to merge later the rest of the missing commits.

My feature branch is just a local one. Naturally I want to avoid rewriting the history.

1

There are 1 answers

2
tlehman On

If the Fix commit is cherry-pickable, then it's independent of D and E, so you could git rebase -i C and reorder your history to put Fix behind D.

Then it would be easy to merge the feature branch back into master.

(master)    A-B-C--Fix'
(feature)        \_Fix-D-E-G-H

You mentioned you wanted to avoid rewriting history, but if you are okay with picking out a single fix commit, I think reordering your feature branch to make it more easily mergable should be acceptable.