How to cancel a local git commit
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
..." to update what will be committed) # (use "git checkout -- ..." 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.
The solution is simply to use the
git reset with
git reset HEAD~1
In addition, on Unix-based system, you can use
HEAD^ which is the same as
^ is not working on Windows as
^ signals a line continuation.
- Dependency injection
- Directives and Pipes
- Data binding
- HTTP Get vs. Post
- Node.js is everywhere
- MongoDB root user
- 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
- Evaluating the Normal Distribution
- What is Nodejs? Advantages and disadvantage?
- How do I debug Nodejs applications?
- Sync directory search using fs.readdirSync