Undo git add before the first commit


As git newbie, this was very tricky but it happens quite often.

You create a new project, say C# project. In case of rails, when you create a new project, it automatically creates .gitignore, but Visual Studio doesn't. You do "git add . " and suddenly you realise you staged so many unnecessary files like resharper cache, dlls, etc.

You don't have any branch yet, as you din't make the first commit. You can't do "git reset ."

Anyway, to make a long story short, you have to

[sourcecode language="bash"]
git rm -r --cached .
[/sourcecode]

 

If you want to have more detailed version of a similar story, go to http://stackoverflow.com/a/682343/437961