How to cancel a local git commit
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
Latest Post
- Dependency injection
- Directives and Pipes
- Data binding
- HTTP Get vs. Post
- Node.js is everywhere
- MongoDB root user
- Combine JavaScript and CSS
- Inline Small JavaScript and CSS
- Minify JavaScript and CSS
- Defer Parsing of JavaScript
- Prefer Async Script Loading
- Components, Bootstrap and DOM
- What is HEAD in git?
- Show the changes in Git.
- What is AngularJS 2?
- Confidence Interval for a Population Mean
- Accuracy vs. Precision
- Sampling Distribution
- Working with the Normal Distribution
- Standardized score - Z score
- Percentile
- Evaluating the Normal Distribution
- What is Nodejs? Advantages and disadvantage?
- How do I debug Nodejs applications?
- Sync directory search using fs.readdirSync