Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amending commit that is edited as part of a rebase in magit

Tags:

git

emacs

magit

I'm using Emacs + it's in very many ways fabulous magit-mode to work with git. There is one aspect of my workflow though that I can't map to this, and thus this question.

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?

like image 338
deets Avatar asked Nov 12 '14 13:11

deets


1 Answers

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:

  1. commit changes to file A (commit 1)
  2. commit changes to file B and file C (commit 2)
  3. commit changes to file D (commit 3)
  4. realize that you want the changes to file B and file C to be separate commits
  5. run magit-log
  6. begin an interactive rebase (E) at commit 2.
  7. specify you want to edit (e) commit 2 and finish (C-cC-c)
  8. return to magit status buffer.
  9. run magit-reset-head (x), specify HEAD~1 in prompt.
  10. you will see the changes for commit 2 staged.
  11. unstage the changes to file C.
  12. commit the staged changes for file B.
  13. stage and commit the changes to file C.
  14. continue and finish the rebase with RC

You will now have four commits, each changing one file in the order A, B, C, D.

like image 108
Jordon Biondo Avatar answered Oct 11 '22 00:10

Jordon Biondo