rqbmjq
Last Updated: February 25, 2016
·
751
· unsignedzero
1642b4962ff22912a5cd7a1fd75fcd9d

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

Say Thanks
Respond

2 Responses
Add your response

13040
Me

i like git clean -df && git checkout . more.

over 1 year ago ·
13284
1642b4962ff22912a5cd7a1fd75fcd9d

@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 ·
Filed Under