撤消git rm。 -r - 缓存或提交更改?

时间:2014-04-08 12:53:34

标签: git gitignore git-rm

我试图让我的.gitingore工作(Link to the question :))。

我刚刚完成了

git rm . -r --cached 

现在,当我输入时,我有一个已删除文件的完整列表:

git status -s 

这是正常的吗? 我可以安全地提交所有更改吗?

或者可能有办法撤消此命令?

PS:我试图理解这个命令的作用,但我只发现了这个:http://brianloomis.wordpress.com/2009/08/10/git-rm-r-cached/ 而且我不太清楚。

PS 2:好的:)为了保存我的皮肤我已经重置了:

git reset HEAD *

DELETED文件再见了:)在git status -s中不再可见。 但是执行命令仍然是安全的:

git rm . -r --cached and then add and commit it? 

1 个答案:

答案 0 :(得分:2)

“安全”?它的作用是清空索引并提交删除这些文件,不用从工作树(你的磁盘)中删除它们

这意味着所有这些文件都被取消跟踪(私有)。

通常,在这样的命令之后你不会提交。你重置了(就像你做的那样) 这可以强制内容驱动程序(如smudge script)或其他.gitattributes指令再次应用于所有文件。

您可以在GitHub帮助页面“Dealing with line endings”中看到该命令。

git rm --cached -r .
# Remove everything from the index.

git reset --hard
# Write both the index and working directory from git's database.

同样,在这种情况下:没有提交,只有重置。