gitgit-rebasegit-interactive-rebase

How do I squash and edit the same commit?


When I do an interactive rebase in git, how do I squash a commit and also stop end edit the same commit?


Solution

  • Add a b or break command after the squash:

    pick 21886dea First commit
    squash 656e9d0e Second commit
    b
    pick e88a69f5 Third commit
    

    After the squash, Git will print something like Stopped at 67a09c7e (Squashed commit). Then you can make edits, run git commit --amend and git rebase --continue.

    The break command was added in Git v2.20.0-rc0, Oct 2018.

    break is slightly different from edit, in that edit lets you skip typing git commit --amend and prints a more relevant message. But, for now, it's the easiest way of doing a squash-then-edit.