git un-remove 在提交之前?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5587183/
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
git un-remove before commit?
提问by John
I accidentally did a
我不小心做了一个
git rm filename.txt -f
git rm filename.txt -f
now if I do a git commit -m ''
, it will commit this delete. How do I un-remove it before I do a git commit?
现在,如果我执行 a git commit -m ''
,它将提交此删除操作。如何在执行 git commit 之前取消删除它?
回答by Cascabel
To get the version from the current commit (HEAD
) into both the index (staging area, what you're about to commit) and the work tree:
要将当前提交 ( HEAD
) 中的版本同时放入索引(暂存区,您将要提交的内容)和工作树中:
git checkout HEAD filename.txt
Note that this isn't just for "unremoval" - it's for getting you back to the version from the commit, whether you've modified it by changing one line or deleting the entire file.
请注意,这不仅仅是为了“取消删除” - 它是为了让您从提交返回到版本,无论您是通过更改一行还是删除整个文件来修改它。
Also, in case others find this looking for a slightly different answer, if you want to get the version from the indexback into the work tree, you can use
此外,如果其他人发现这寻找略有不同的答案,如果您想将索引中的版本重新放入工作树,您可以使用
git checkout filename.txt
That's handy for when you manage to stage everything for a commit, then do something stupid (like remove a file) - you can save yourself by recovering from the index.
当您设法为提交暂存所有内容,然后做一些愚蠢的事情(例如删除文件)时,这很方便 - 您可以通过从索引中恢复来拯救自己。