Amending commit that is edited as part of a rebase in magit
Sometimes you have a commit which should be reworked into separate commits. I can interactively rebase my commits with magit, and declare my intend to edit said commit.
Now I have to switch over to git gui, select “ammend last commit” which shows me the staged changes, and unstage those parts I want to become a separate commit. Then I commit, stage the exclusions, and commit again – voila, I have a new commit within my history.
I have so far not found a way to accomplish this using Emacs. Any hints?
One Solution collect form web for “Amending commit that is edited as part of a rebase in magit”
After your begin the rebase, instead of going to the gui, do a magit-reset-head to HEAD~1, this will put you in the position to unstage the changes, and stage and commit as desired before finally Continuing the rebase from the magit status buffer.
Example scenario workflow:
- commit changes to file A (commit 1)
- commit changes to file B and file C (commit 2)
- commit changes to file D (commit 3)
- realize that you want the changes to file B and file C to be separate commits
- begin an interactive rebase (E) at commit 2.
- specify you want to edit (e) commit 2 and finish (C-cC-c)
- return to magit status buffer.
- you will see the changes for commit 2 staged.
- unstage the changes to file C.
- commit the staged changes for file B.
- stage and commit the changes to file C.
- continue and finish the rebase with RC
You will now have four commits, each changing one file in the order A, B, C, D.