tags:

views:

42

answers:

1

1) I did git init in a folder

2) added some project files

3) I did git add * so it added recursively all files

4) I realised that I added a bunch of files I don't want to be versioned, so I wanted to undo the add

5) git reset gives me the following error:

fatal: Failed to resolve 'HEAD' as a valid ref.

6) git status still shows all the added files

7) I tried git reset --hard HEAD and I got the following error:

fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

8) git status still shows all the added files

What should I do at this point?

+3  A: 
git rm [-r] --cache -- <file>…

would be the right command to remove from the index the file you don't want to commit.
Any reset command won't work, since you have to any commit yet in your newly created repository.

From the git rm man page:

--cached

Use this option to unstage and remove paths only from the index.
Working tree files, whether modified or not, will be left alone.

-r

Allow recursive removal when a leading directory name is given.

<file>…

Files to remove.
Fileglobs (e.g. *.c) can be given to remove all matching files. If you want git to expand file glob characters, you may need to shell-escape them.
A leading directory name (e.g. dir to remove dir/file1 and dir/file2) can be given to remove all files in the directory, and recursively all sub-directories, but this requires the -r option to be explicitly given.

VonC
git rm -r --cached for directories and without the -r for individual files worked out. thanks!
lurscher
@lurscher: good point. I have updated the answer to reflect the 'recursive' `-r` option.
VonC