View 3+ more - How do I undo 'git add' before commit?

github / git

I mistakenly added files to Git using the command:

git add myfile.txt

Braiam



Answer #1

Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

 git reset HEAD <file>

Reset the file to the last state from HEAD, undoing changes and removing them from the index:

 # Think `svn revert <file>` IIRC.
 git reset HEAD <file>
 git checkout <file>

 # If you have a `<branch>` named like `<file>`, use:
 git checkout -- <file>
 git rm --cached <file>
 git rm <file>