git - Is there a better way to accomplish the combination reset, checkout, cherry-pick, checkout, rebase? -
suppose have following history:
a ─▶ b -- master ╲ ◀ c ─▶ d ─▶ e -- feature
at point e
, stuble upon small bug in code has strictly speaking nothing feature
, happens important @ point, though went unnoticed. i'll first of fix right in place:
a ─▶ b -- master ╲ ◀ c ─▶ d ─▶ e ─▶ f -- feature ⋮ fix bug
but, since after bug has not feature
such, isn't history want – fix should right in master
(if not in dedicated bugfix branch).
git checkout master git cherry-pick f ─▶ b ─▶ f' -- master ╲ ◀ c ─▶ d ─▶ e ─▶ f -- feature
ok, fine, can't leave @ (or can i?) – f
occurs 2 times in active branches yet want merge. could
git checkout feature git reset --hard head^ ─▶ b ─▶ f' -- master ╲ ◀ c ─▶ d ─▶ e -- feature
and wait f'
when merging feature
master
, won't because don't have bugfix available right need – work on feature
. i'll finish off with
git rebase master ─▶ b ─▶ f' -- master ╲ ◀ c' ─▶ d' ─▶ e' -- feature
this feels complicated , error-prone way of achieving goal, moving single commit in history.
is there more straghtforward way accomplish task?
summary
in opinion easiest way fix bug directly on master
(or in bugfix branch based on master
). after master
includes bugfix can rebase feature branch onto master
. done.
detailed flow (with bugfix branch)
bugfix branch:
git checkout master && git checkout -b bugfix * 98f2c4f (head -> bugfix) bugfix commit | * efe77fd (feature1) test2 |/ * 3c3a2ee (master) test
merge bugfix
master
, delete bugfix
:
git checkout master && git merge bugfix && git branch -d bugfix * 98f2c4f (head -> master) bugfix commit | * efe77fd (feature1) test2 |/ * 3c3a2ee test
rebase feature branch onto master
:
git checkout feature1 && git rebase master * e3a55ed (head -> feature1) test2 * 98f2c4f (master) bugfix commit * 3c3a2ee test
Comments
Post a Comment