如何在git init之后撤消git添加文件

如何在git init之后撤消git添加文件,git,version-control,Git,Version Control,我刚刚在git init之后添加了一堆文件。现在我注意到我犯了一个错误,我想立即撤销所有错误。我该怎么做 $ 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 fi

我刚刚在git init之后添加了一堆文件。现在我注意到我犯了一个错误,我想立即撤销所有错误。我该怎么做

$ 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
...

你得到了正确的命令。(在这种特殊情况下,除了
reset
,因为您还没有头部-因为没有提交。但是
reset
通常可以工作)

你唯一错过的是Git可以采用全局模式

git rm --cached *

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

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

我按照您的建议进行了尝试,但无法使用子文件夹。输出告诉我将-r(递归地)放入
git rm-r--cached*
。它就像一个符咒。
git rm --cached *