1

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
4

2 回答 2

3

你得到了正确的命令。(在这种特殊情况下除外reset,因为您还没有 HEAD - 因为没有提交。但reset通常会起作用)。

你唯一想念的是 Git 可以采用 glob 模式。

git rm --cached *

所以这样你就不必单独传递每个文件。请注意,在您第一次提交之后,您需要为此使用 soft reset(git rm 也会删除已提交的文件)。

于 2013-10-22T15:44:36.380 回答
0

如果它是一个新存储库,您只需删除项目中的.git文件夹,然后再次初始化 git 存储库。

于 2013-10-22T15:44:44.477 回答