Git reset - hard

How to use git reset --hard

You are here since you need to undo/revert your changes.

Important note:

Scenario 1:

You can undo/revert all your changes with:

git reset --hard

Scenario 2:

You can undo/revert all your changes with:

git reset --hard

Scenario 3:

You can undo/revert all your changes in your tracked files with:

git reset --hard

This command will only reset (undo/revert) all the changes inside the tracked files inside the main directory or any other directories.

This command does not touch any new (untracked) files inside the main or any other directories , since you have not staged them.

You need first to look at my other blog post (here) and then come back here.

Scenario 4:

This command will undo/revert all your changes in tracked files and also REMOVE all the untracked new files which are staged.

git reset --hard

It means for staged untracked new files when running the above command, the following command will also be run:

git clean -f -d

In conclusion:

git reset --hard

To understand the above command you need to read this.

Learn More:

This also is equivalent:

git reset --hard HEAD

where HEAD is the last commit in your current branch

HEAD is simply a reference to the current commit (latest) on the current branch. There can only be a single HEAD at any given time (excluding git worktree).

The content of HEAD is stored inside .git/HEAD, and it contains the 40 bytes SHA-1 of the current commit.

Posting daily about Python, Laravel