Amending commit that is edited as part of a rebase in 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.

  • How do I make Git use the editor of my choice for commits?
  • Which version control system or platform is the best one for tracking and distributing personal Emacs configurations?
  • Why would you use Dropbox but also Git for your Emacs initialization file?
  • Following a link into a git-repo without lengthy dialog
  • How to revert a change from older commit in `magit`?
  • How do I merge branches with Magit using a new commit object?
  • 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?

  • Getting the remotes along when pulling a local repo
  • Embed Git bash in PyCharm as external tool and work with it in PyCharm window
  • How to change author email at commit time with hooks
  • Clone only one branch
  • Python not working in the command line of git bash
  • git bash fail to push branch with error message: “object directory does not exist”
  • 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:

    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.

    Git Baby is a git and github fan, let's start git clone.