Suppose I have the following history:
A ─▶ B -- master
╲
◀
C ─▶ D ─▶ E -- feature
At point E
, I stuble upon a small bug in the code that has strictly speaking nothing to do with feature
, but happens to be important at this point, though it previously went unnoticed. I'll then first of all fix it right in place:
A ─▶ B -- master
╲
◀
C ─▶ D ─▶ E ─▶ F -- feature
⋮
fix bug
But, since it is after all a bug that has not much to do with feature
as such, this isn't really the history I want – this fix should be right in master
(if not in a dedicated bugfix branch).
git checkout master
git cherry-pick F
A ─▶ B ─▶ F' -- master
╲
◀
C ─▶ D ─▶ E ─▶ F -- feature
Ok, fine, but I can't really leave it at this (or can I?) – F
now occurs two times in active branches that I yet want to merge. I could
git checkout feature
git reset --hard HEAD^
A ─▶ B ─▶ F' -- master
╲
◀
C ─▶ D ─▶ E -- feature
and wait for F'
when merging feature
back into master
, but that won't do because I don't have the bugfix available right where I need it – for the work on feature
. So I'll then finish it off with
git rebase master
A ─▶ B ─▶ F' -- master
╲
◀
C' ─▶ D' ─▶ E' -- feature
This feels a complicated and somewhat error-prone way of achieving the goal, which is essentially just moving a single commit up in the history.
Is there a more straghtforward way to accomplish this task?