I mistakenly added files to Git using the command:
git add myfile.txt
I have not yet run git commit
. How do I undo this so that these changes will not be included in the commit?
gitgit-addundo
I mistakenly added files to Git using the command:
git add myfile.txt
I have not yet run git commit
. How do I undo this so that these changes will not be included in the commit?
Best Answer
To unstage a specific file
That will remove the file from the current index (the "about to be committed" list) without changing anything else.
To unstage all files from the current change set:
In old versions of Git, the above commands are equivalent to
git reset HEAD <file>
andgit reset HEAD
respectively, and will fail ifHEAD
is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch calledHEAD
, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:Documentation: git reset