How To Git Hard Reset Head?

Git provides the HEAD which is the latest commit. After the latest commit, some changes can make for different files and folders. These changes are stored permanently with the next commit. But if you want to reset all changes after the last commit and revert to the head you should hard reset the head with git.

List Changes

After making a commit we can make changes like editing an existing file, adding new file or folder. These changes are simply made after the last commit which is named as HEAD . The changes made after HEAD can be listed with the git status command below.

$ git status
List Changes

Git Hard Reset Head

The git reset --hard resets to the current HEAD but it also removes all uncommitted changes which can not be reverted back. It is best to use the git status command before executing “git reset –hard” command in order to list uncommitted changes.

$ git reset --hard HEAD
HEAD is now at 705ac8d97 Added links and references from Nmap Thid Party Open Source to Npcap's Third Party Open Source file.

Git Hard Reset Previous Than Head

We can also reset previous commit than the current HEAD by using the HEAD~1 which means the previous commit than HEAD.

$ git reset --hard HEAD~1

Leave a Comment