Reputation: 8913
I committed a java file using
git commit -a
I forgot to add a file to said commit so I tried to amend the previous one using
git commit -a --amend
When the editor opened up, I changed my mind and closed the editor using :q!
.
I then did a git log and my unintentional commit was successful.
Anyone know why git went ahead and committed my 'aborted' commit?
Upvotes: 1
Views: 134
Reputation: 80639
When you amend a commit, irrespective of whether you forcefully quit the editor or anything, the amend will be successful as long as the commit message was not empty when the .git/COMMIT_MESSAGE
file was last saved.
So, with git commit --amend
, if you previously had a commit message; you'd need to remove the entire message and then save the buffer. When you quit the edit, the amend step will be aborted.
Upvotes: 1