DEV Community

Cover image for GIT RESET
Mohamed Yahia
Mohamed Yahia

Posted on



My most common usecase for git reset is when i stage changes by mistake. Maybe i make some changes that involve multiple things and i want to divide them into seperate commits.

Image description

If you add them, git tells you this

Image description

use "git restore --staged <file>..." to unstage
Enter fullscreen mode Exit fullscreen mode

since you know . denotes the whole directory, you try git restore --staged . and it unstages the changes. Here comes reset with its shorter syntax, just git reset and voila your changes are gone.


git reset is mainly used to undo commits.
git reset <commit hash> and it will delete all commits up until that commit and most importantly KEEP THE CHANGES or to be most specific move the changes to the working directory.

That's why git reset without providing a commit, moves changes from the staging area to the working directory

git reset --hard deletes the changes so if you run this command bare it will delete the working directory and the staging area GONE but UNTRACKED FILES ARE NOT AFFECTED.

This behavior for untracked files is the same with any git reset command, it's not specific to the hard option.

git reset --hard <commit hash> will delete changes up to that commit.

Top comments (1)

eminaltan profile image
Emin Altan

What's the diffrence git checkout --filename with git reset --filename