Last Updated On By Khizer Ali
Committing changes is a regular phenomenon when you work with Git. The traditional workflow of Git is such that you build your project in modules or pieces, add them up to the staging area, and commit them in the working tree. After committing, your code becomes ready to push on the remote repository.
However, if you have ever been in a situation where after committing changes or files, you realize that you just made a mistake that you don’t want to push, or you have forgotten to add a file, then this guide is for you to walk through the mechanism of uncommitting changes in Git.
Table of Contents
$ git reset HEAD^
$ git reset --soft HEAD^
$ git reset --hard HEAD^
$ git reset HEAD~2
$ git reset [commit_hash]
If you are a Windows user, keep the hash commit number or HEAD within double-quotes. For example:
$ git reset “HEAD^”
$ git reset “f145h7r”