Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

16
  • 160
    Of course, this is not a true undo, because if the wrong git add overwrote a previous staged uncommited version, we can't recover it. I tried to clarify this in my answer below.
    – leonbloy
    Commented May 6, 2013 at 19:10
  • 12
    git reset HEAD *.ext where ext is the files of the given extension you want to unadd. For me it was *.bmp & *.zip Commented Nov 26, 2013 at 14:25
  • 28
    @Jonny, the index (aka staging area) contains all the files, not just changed files. It "starts life" (when you check out a commit or clone a repo) as a copy of all the files in the commit pointed to by HEAD. So if you remove a file from the index (git rm --cached) it means you are preparing to make a commit that deletes that file. git reset HEAD <filename> on the other hand will copy the file from HEAD to the index, so that the next commit won't show any changes being made to that file.
    – Wildcard
    Commented Mar 16, 2016 at 12:27
  • 23
    I just discovered that there is a git reset -p just like git add -p. This is awesome!
    – donquixote
    Commented Jul 17, 2016 at 23:23
  • 23
    You actually can recover overwriten previously staged but uncommited changes but not in a userfriendly way and not 100% secure (at least none I had found): goto .git/objects, search for files created at the time of git add you want to recover (61/3AF3... -> object id 613AF3...), then git cat-file -p <object-id> (might be worth it to recover several hours of work but also a lesson to commit more often...) Commented Jul 31, 2017 at 14:03