Reputation: 1774
I have just added a bunch of files after I git init. Now I notice that I've made a mistake and want to undo all of them at once. How can I do that?
$ git init
$ git add .
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: .DS_Store
# new file: .gitignore
# new file: .idea/.generators
# new file: .idea/.name
# new file: .idea/.rakeTasks
# new file: .idea/DAM.iml
...
git rm --cached <file>
will need to specify all files individually. I'd like to do it in a single command. Is it possible?
I did git reset HEAD
, but it doesn't help.
$ git reset HEAD
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
Upvotes: 1
Views: 498
Reputation: 2512
If its a new repository, you can just remove the .git folder inside your project and then initialize the git repository again.
Upvotes: 0
Reputation: 44619
You got the right commands. (Except reset
in this particular case because you have no HEAD yet - as there's no commits. But reset
would usually work).
The only you miss is that Git can take glob patterns.
git rm --cached *
So this way you won't have to pass each file individually. Note that after your first commit you'll want to use soft reset
for this (git rm would remove commited file too).
Upvotes: 3