How to cancel a local git commit? How to cancel a local git commit? git git

How to cancel a local git commit?


Just use git reset without the --hard flag:

git reset HEAD~1

PS: On Unix based systems you can use HEAD^ which is equal to HEAD~1. On Windows HEAD^ will not work because ^ signals a line continuation. So your command prompt will just ask you More?.


Use --soft instead of --hard flag:

git reset --soft HEAD^

It will remove the last local (unpushed) commit, but will keep changes you have done.


If you're in the middle of a commit (i.e. in your editor already), you can cancel it by deleting all lines above the first #. That will abort the commit.

So you can delete all lines so that the commit message is empty, then save the file:

It should look like this.

You'll then get a message that says Aborting commit due to empty commit message..