Mar 232010
 
Q In Git you have your working tree and your repository but the necessary in-between state is the staging area. Files get staged by doing a git add. What’s the opposite of a git add, i.e. how can I “unstage” a file?
A Updated 25 August 2011.

    Embarrassingly, I just saw the comments now over a year later and it turns out I have a lot to learn with GIT, I have not used it enough and got this completely wrong as the comments testify. I leave my deleted answer for my own education. I have turned on comment notification now!

      As the handy command line help on a git status shows, files can be unstaged with git rm.

        To wipe any changes you have made since the last commit, do a git reset HEAD <file name with complete path>

         Posted by on March 23 2010  Tagged with:

          7 Responses to “Git Tip: unstaging”

        1. This is completely wrong. As git itself suggests when you do a git status, you do git reset HEAD to unstage a file. git rm will actually delete the file and stage the changes. If you have a file stages, and try to rm, git will not do it and tell you that you can’t do that as it’s staged, or you have to use the force switch.

        2. this is totally wrong!
          etylocus is right.

        3. This is one of the top “g.i.t u.n.s.t.a.g.e” Google hits (I added the dots to hopefully avoid bumping it even higher).

          Please fix or delete it.

        4. Yeah man. This is wrong. Please delete.

        5. This comment has been removed by the author.

        6. Posting the real answer would be of more value than deleting the post! 🙂

          The right way to undo ‘git add [paths]’ is ‘git reset [paths]’

          Answer from http://stackoverflow.com/questions/348170/undo-git-add-before-commit

        7. On the other hand, despite the error, this thread still solved my problem.

          Maybe Google knows all to well.