Git commit --amend is evil
I have been using git commit -amend
for some obvious purposes like
- Updating last commit message
- Forgot to add new files to previous commit or want to add some more changes to a file of previous commit
As for as I used it for updating commit message, everything was fine, but then I started using it for the later purpose and things became messy sometimes.
While coding, I am used to commit quite often and many times I want to change same file that I checked in my previous commit and git commit -a was the easy and obvious candidate for that. But, sometime I find the last amend was the evil(e.g. introduced a bug in the amend), and I simply cannot rollback file’s state to one before the amend because I overwrite revision history of that file,
Ok, How I do it now ? What is the solution?
Now, I do not use amend anymore. I just keep committing new versions every time I change any file and at the end, when I feel everything is fine and ready to push, I use git rebase -i
to merge all the commit as a single one.