I have a repo that is pushed to a remote and downloaded by others. Within the history is a bug introduced by a commit I made. Embarrassingly that commit it unwieldy (too much logic in one commit). Aside from going back in time and whacking my past self with a wet noodle the proper thing to do would be an interactive rebase to split the commit into several.
Sadly this has already been pushed and cloned by others (who would be very unpleased if I rebased from underneath them). So I thought I could branch, revert commit, cherry-pick commit, interactive rebase, then merge. Is this the best option or am I missing something?
Can I split a published commit by reverting then splitting?
A--B--C--D--E--F (master origin/master)
^- WTF commit
A--B--C--D--E--F-------------------M (master origin/master)
\ /
G--C1--C2--C3--C4 (split-and-fix-branch)
^- revert commit C
So my instinct is correct. The following lays out how to split/edit a commit that has already been pushed and pulled.
EDIT: Modified procedure with suggestions from comments.
If this is local only use get rebase -i
instead.
A--B--C--D--E--F (master origin/master)
^- WTF Commit
$ git checkout -b split-n-fix C
A--B--C--D--E--F (master origin/master)
^ (split-n-fix)
$ git revert C
A--B--C--D--E--F (master origin/master)
\
R (split-n-fix)
$ git cherry-pick --no-commit C
A--B--C--D--E--F (master origin/master)
\
R--(dirty) (split-n-fix)
$ git add -p
$ git commit
(repeat till finished)
A--B--C--D--E--F (master origin/master)
\
R--C1--C2--C3--C4 (split-n-fix)
$ git checkout master
$ git merge split-n-fix
$ git branch -d split-n-fix
A--B--C--D--E--F----------M (master origin/master)
\ /
R--C1--C2--C3--C4
$ git push
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句