35 Fixing Commits

One of the advantages of Git is the ability to “fix” commits. Fixing changes can be as simple as fixing typos that got committed, fixing a bug you didn’t catch because you hadn’t run your unit tests yet, or doing something as complex as rearranging an entire series of commits so they are ordered more logically.

git commit --amend is the way to fix the most recent commit. It comes in handy for those simple fixes that you catch right away. It is a convenience wrapper around using git reset --soft HEAD^ (see Task 37, ​Resetting Staged Changes and Commits​) and git commit -c ORIG_HEAD. You can use the -C parameter with --amend when you want to reuse the original commit message.

You can use git rebase -i to replay ...

Get Pragmatic Guide to Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.