Git - 撤消 git rm

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13698978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:02:02  来源:igfitidea点击:

Git - undoing git rm

gitgit-rm

提问by user1436111

Possible Duplicate:
How to revert a “git rm -r .”?

可能的重复:
如何恢复“git rm -r .”?

Git SOS here. I worked 10 hours on a project without committing (I know, I know) and then I git added too many files, so I tried using git rm and accidentally deleted EVERYTHING. Is there hope for me? :(((

Git SOS 在这里。我在一个项目上工作了 10 个小时没有提交(我知道,我知道)然后我 git 添加了太多文件,所以我尝试使用 git rm 并意外删除了所有内容。我还有希望吗?:(((

回答by Hauleth

If you already commited changes, then:

如果您已经提交更改,则:

git reset (--hard) HEAD~1

If not then:

如果没有,那么:

git reset
git ls-files -d -z | xargs -0 git checkout --