For a lot of us, version control does two things which are contradictory:
- it keeps checkpoints as we work so we can easily roll back, and
- wraps up our work into a tidy package for others to use.
git commit --amend
is one tool that solves this. It will “open up” the previous commit, adding staged files and allowing you to re-edit the commit message.
- Make your “checkpoint” commit, e.g. with a failing spec.
- Get your specs working again.
- Stage your changes like you normally would using
git add
. - Instead of git commit, do
git commit --amend
. - Edit the message to describe the feature. This will be the commit’s new message, and it will contain all the changes.
A related command: git rebase -i
(“interactive”). If you didn’t use --amend
, you can go back and condense commits together as if you had. With this command, you can interactively rebase, using the “squash” command to combine multiple commits together.