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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 HEADrespectively, and will fail ifHEADis 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