Skip to main content
34 events
when toggle format what by license comment
Apr 28 at 22:24 comment added doctorram You can use "git restore --staged <file>" to unstage files now.
Oct 31, 2023 at 11:16 comment added veritas this worked for me when I am in the same folder as the file and do git reset <fullfilenamewithextension>
Oct 30, 2023 at 8:09 comment added fresko why they don't add a command called UNDO, to be used with many commands? I have to learn 200 commands and parameters that i forget after 3 seconds. Somebody should create a friendly version of GIT
Oct 11, 2023 at 2:02 history edited Shyam Habarakada CC BY-SA 4.0
Highlighted the two main use-cases with formatting and a bit of editing.
Jul 5, 2022 at 0:18 history edited Mateen Ulhaq CC BY-SA 4.0
Shorten.
Oct 14, 2020 at 10:18 comment added crobar I don't know if I did this right, but git reset <file> seemed to also delete the file from my file system as well, which is obviously not what you want.
S Jun 25, 2020 at 12:10 history suggested Manu Sharma CC BY-SA 4.0
Added documentation for git reset.
Jun 23, 2020 at 21:01 review Suggested edits
S Jun 25, 2020 at 12:10
Jan 22, 2020 at 19:22 comment added akgupta I have also added some files from a common library to the stage. Since, it is an angular app, so I had to use git reset */commonlib/styles/*.scss to locate all such files and it worked.
Nov 20, 2019 at 19:31 comment added Bill Hoag As of git 2.23.0, there is now "git restore --staged <file>..." to unstage. See stackoverflow.com/a/16044987/40422
Nov 3, 2019 at 13:07 history edited Peter Mortensen CC BY-SA 4.0
Expanded.
Apr 27, 2018 at 15:27 comment added iolsmit Another way to recover changes that were staged but not committed and then overwritten by e.g. another git add is via git fsck --unreachable that will list all unreachable obj, which you can then inspect by git show SHA-1_ID or git fsck --lost-found that will >Write dangling objects into .git/lost-found/commit/ or .git/lost-found/other/, depending on type. See also git fsck --help
Jul 31, 2017 at 14:03 comment added Peter Schneider 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...)
Feb 17, 2017 at 16:29 comment added Arthur but 'git reset file' removes other files that had been staged for commit too. not good.
Dec 15, 2016 at 18:33 comment added machineghost -p most definitely is awesome, and it's used in a lot of git commands (not just reset and add). But to answer @WeDoTDD.com and @Johnny, git reset by itself just clears whether Git "knows about" the changes; it doesn't clear the changes themselves. To do that you need to do git checkout someFile.txt (for individual files) or git reset --hard (to wipe everything clean). There's no going back from either of these commands though, so be very careful when using them.
Jul 17, 2016 at 23:23 comment added donquixote I just discovered that there is a git reset -p just like git add -p. This is awesome!
Mar 16, 2016 at 12:27 comment added Wildcard @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.
Feb 17, 2016 at 5:53 comment added Jonny So the opposite of "add" is "reset"? What about "remove"?
Oct 29, 2015 at 23:04 history edited Mark Amery CC BY-SA 3.0
add note that on old version of Git this didn't work prior to first commit
Oct 29, 2015 at 22:45 history edited Mark Amery CC BY-SA 3.0
Give `git reset` a full line, and remove claim about `git reset foo` and `git reset HEAD foo` being equivalent - this is false! The former works when HEAD is undefined (because you've just `git init`ed and haven't yet committed) or ambiguous (because you're a dick and created a branch called HEAD)
Oct 16, 2015 at 3:39 comment added PositiveGuy git reset said it undid the changes but when I proceeded to do another git status, they still showed modified
Jun 26, 2015 at 15:14 history edited Jim Fell CC BY-SA 3.0
Clarified response, so that it can stand on its own, and will not appear out of context.
Jun 16, 2015 at 18:29 history edited iconoclast CC BY-SA 3.0
grammar and readability and pedantic accuracy
Nov 24, 2014 at 0:38 review Suggested edits
Nov 24, 2014 at 0:57
Apr 29, 2014 at 19:39 history edited AlexStack CC BY-SA 3.0
added some more info
Apr 5, 2014 at 5:55 history edited user456814 CC BY-SA 3.0
Improved formatting.
Apr 5, 2014 at 5:27 history edited user456814 CC BY-SA 3.0
Made it clear that HEAD is optional.
Nov 26, 2013 at 14:25 comment added boulder_ruby git reset HEAD *.ext where ext is the files of the given extension you want to unadd. For me it was *.bmp & *.zip
May 6, 2013 at 19:10 comment added leonbloy 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.
May 1, 2013 at 11:08 history edited iwein CC BY-SA 3.0
adds HEAD to the command, often optional, but still good to show here.
Dec 31, 2011 at 0:45 review Suggested edits
Dec 31, 2011 at 0:56
Oct 30, 2010 at 10:56 history edited takeshin CC BY-SA 2.5
formatting
Dec 8, 2008 at 0:12 vote accept oz10
Dec 7, 2008 at 22:30 history answered genehack CC BY-SA 2.5