Timeline for How do I undo 'git add' before commit?
Current License: CC BY-SA 4.0
35 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 30 at 1:34 | comment | added | TheMet4lGod |
git reset works if you accidentally stage all of your project files before adding your .gitignore . At least it worked for me. I suppose it's harder if you have already pushed to remote.
|
|
Oct 14, 2021 at 7:40 | comment | added | Valerij Dobler | if it was your first commit Just remove the .git directory and init again. | |
Dec 28, 2020 at 23:56 | comment | added | Ahmad | I just discovered that there is a git reset -p just like git add -p. This is awesome! | |
Jun 29, 2020 at 17:15 | comment | added | TheTechRobo the Nerd | @ahnbizcad ...well, once you know what you're doing, it's much easier,...and I find the GUI too bloated and too much mouse movement...so it's a matter of opinion. | |
Feb 18, 2019 at 8:43 | comment | added | bhavya_w | This command CLEARS / DELETES STUFF IN THE INDEX. What the OP and other people actually want is to UNDO THE CHANGES IN THE INDEX and NOT DELETE STUFF. Git reset . is the correct answer. | |
Sep 13, 2018 at 0:05 | history | edited | codeforester | CC BY-SA 4.0 |
added 3 characters in body
|
Jul 4, 2018 at 17:06 | review | Suggested edits | |||
Jul 5, 2018 at 0:22 | |||||
Oct 20, 2016 at 1:46 | comment | added | Ding-Yi Chen |
If the files have not yet in index, use git rm --cache <filename> , if the files already in index, but you don't want them to be in this commit, use git reset <filename>
|
|
Apr 5, 2016 at 14:16 | comment | added | Kevin Lee | Why not just delete the hidden .git folder lol.. and do git init again... (assuming you're making the git repo for the FIRST time and have not done any commits) | |
Oct 20, 2015 at 11:31 | comment | added | rew | When intially populating a git repository, "git reset" from the top answer doesn't work: failed to resolve HEAD. We added a single file too many to the initial commit. As suggested by this answer, in that case "git rm --cached <file>" works for me. Maybe "git rm --cached ." does more than is intended for some people, but (as suggested by git status), git rm --cached <file> works.... | |
Sep 4, 2014 at 6:45 | review | Suggested edits | |||
Sep 4, 2014 at 7:02 | |||||
Jun 3, 2014 at 17:33 | comment | added | JoeMoe1984 |
@BarryKelly I tried to edit my comment as I reread yours but I was too late. I missed that part of what you wrote ;). But yeah you're right, that would be another instance to use git rm --cached
|
|
Jun 2, 2014 at 21:14 | comment | added | JoeMoe1984 |
@BarryKelly no it is not the correct answer. What you actually want to do is either git reset to undo all added files or git reset <file> to undo a specific added file. git rm --cached may work on the surface but what actually happens is it removes it from the tracking history as well which is not what you would want to do, unless, you added that file to a gitignore file where that file shouldn't have been tracked in the first place then in that case it would be ok.
|
|
May 24, 2014 at 10:54 | comment | added | ahnbizcad | just goes to show how unintuitive and convoluted git is. instead of having parallel "undo" commands, you have to find out how to undo them. Like trying to free your leg in quick sand, and then getting your arm stuck, then getting your other arm stuck... every command should be done through GUI, with dropdown menus items for the options... Think of all the UI, productivity gains we've had, but we have this mess of a retro command line interface. It's not like the git GUI programs make this any more intuitive. | |
Apr 10, 2014 at 16:34 | review | Low quality answers | |||
Apr 10, 2014 at 16:56 | |||||
Aug 28, 2013 at 18:25 | comment | added | akostadinov |
according to git status output of git version 1.8.1.4 the correct way to unstage new files is: git reset HEAD <file>...
|
|
Jul 14, 2013 at 22:28 | comment | added | deed02392 |
I certainly feel if this is a totally new repository, removing the .git directory and initialising again is the best way. For cases in a well-used repo where you just accidentally added a single file, git rm --cached <file> seems best although I get a scary delete mode 100644 file after my commit.
|
|
Apr 10, 2013 at 2:37 | review | Suggested edits | |||
Apr 10, 2013 at 2:43 | |||||
Apr 10, 2013 at 2:33 | comment | added | naught101 |
This will actually work, but only on the first commit, where the file didn't exist before, or where the git add command added new files, but not changes to existing files.
|
|
Mar 9, 2013 at 11:13 | history | edited | Peter Mortensen | CC BY-SA 3.0 |
Copy edited. Removed historical information.
|
Feb 28, 2013 at 22:14 | comment | added | Barry Kelly | git rm --cached <file> is actually the correct answer, if it is the initial import of <file> into the repository. If you're trying to unstage a change to the file, git reset is the correct answer. People saying that this answer is wrong are thinking of a different question. | |
Nov 3, 2012 at 19:05 | comment | added | chachan |
You also could use git stash/git stash pop to avoid zipping/backing up everything
|
|
Sep 12, 2012 at 6:50 | comment | added | drahnr |
For me git says git reset HEAD <File>...
|
|
Apr 28, 2012 at 22:05 | comment | added | jlundqvist |
Instead of the dry run, walk through the add with git add -p
|
|
S Jan 28, 2012 at 22:29 | history | suggested | Grhm | CC BY-SA 3.0 |
Added answer at top, so reader doesn't see the first `git reset` and miss the actual answer later on.
|
Jan 28, 2012 at 21:05 | review | Suggested edits | |||
S Jan 28, 2012 at 22:29 | |||||
Dec 9, 2011 at 21:58 | comment | added | Marius Butuc |
If you like git reset , try git reset * instead of git reset . - it un-stages all you previously staged files.
|
|
Nov 22, 2011 at 15:23 | comment | added | Tom Davies |
in recent versions of git (v1.7.1.1 tested ) git rm -r --cached . works fine
|
|
Oct 28, 2011 at 9:53 | review | Suggested edits | |||
Oct 28, 2011 at 10:22 | |||||
Jun 1, 2011 at 9:09 | comment | added | SamGoody | Did this and it deleted all my other existing files - unchanged - from the git backup. Re-adding them makes everything larger and destroys the proper history. Git is totally an unfinished project. | |
Mar 29, 2011 at 3:45 | comment | added | Adrian Macneil |
Hah. I followed this same process. Except I gave up and said rm -rf .git , git init because I didn't trust git rm --cached to keep my working copy. It says a little for how git is still overly complex in some places. git unstage should just be a stock standard command, I don't care if I can add it as an alias.
|
|
May 26, 2010 at 14:40 | history | edited | Drew Noakes | CC BY-SA 2.5 |
Added period to "git add -n ." example. Some formatting.
|
Nov 11, 2009 at 12:21 | comment | added | ustun | Doesn't just "git reset" without . do what you want, or am I missing something? | |
Mar 25, 2009 at 16:32 | history | edited | Rhubarb | CC BY-SA 2.5 |
added 1472 characters in body
|
Mar 25, 2009 at 16:20 | history | answered | Rhubarb | CC BY-SA 2.5 |