The Issue

The issue is I have changed a file, e.g. app.js, added some new code and saved the file, then I run the following commands:

git status
 
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#  modified:   run.js
#
no changes added to commit (use "git add" and/or "git commit -a")
 
 
git add run.js
 
git commit -a -m 'Some changes to run.js'

I have NOT pushed the commit to remove repo, and now I want to cancel this local commit.

Solution

The solution is simply to use the git reset with HEAD~1.

git reset HEAD~1

In addition, on Unix-based system, you can use HEAD^ which is the same as HEAD~1. But ^ is not working on Windows as ^ signals a line continuation.

Reference

  • N/A