Git reset

Git reset un-commit tracked changes. After a reset, you see commits are removed when you check the git log. The removed changes are put into your working directory, either in staging area or un-tracked changes.

There are three options to perform a reset.

git reset --soft

git reset (No option)

git reset --hard

NOTE: A git reset --hard delete the commit without putting back the changes into working directory. It means those changes are lost.

We need to understand the three stages for file changes.

Example of reset the last commit

git reset HEAD~1

The HEAD~1 means 1 commit before HEAD.

Referencing commits by relative path

When we call git reset, we need to specific how many commits to reset. We often use a relative reference. HEAD~1 means 1 commit before HEAD. HEAD~2 means 2 commits before HEAD.

NOTE: HEAD^ also means 1 commit before HEAD.