Last Updated: March 15, 2021
·
1.012K
· unsignedzero

Undoing a git add

Sometimes you might accidentally add a file you didn't want, or added it and don't want it staged for a commit.

You can undo this with:

git reset HEAD <file>

This will NOT remove the file. This simply unstages it and the git repo sees it as a "new" file" that can be staged. This is compared to:

git rm --cached <file>

This removes the file from the repo but doesn't actually rm the file itself. If --cached is removed, the file will be removed. Be careful and commit often.

Reference: https://stackoverflow.com/questions/6919121/why-are-there-2-ways-to-unstage-a-file-in-git

1 Response
Add your response

@excitedubai The only issue is that it targets the repo base directory itself. The above targets one file but that's useful when you want to reset.

I'd add git reset --hard HEAD for that but cleaning is much nicer.

over 1 year ago ·