git rm --cached 文件与 git 重置文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12661306/
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 14:42:16  来源:igfitidea点击:

git rm --cached file vs git reset file

gitgit-resetgit-rm

提问by Vihaan Verma

I'm trying to learn Git. I'm confused between

我正在努力学习 Git。我很困惑

git rm --cached file

and

git reset file

both of the commands seem to take the file from staged to un-staged area. How do the commands differ?

这两个命令似乎都将文件从暂存区带到未暂存区。命令有何不同?

回答by CB Bailey

git rm --cached <file>will completely remove the file's contents from the index. This means that on commit the file will be removed from the HEADcommit. (If the file was only added to the index and not yet tracked this is a "no-op".)

git rm --cached <file>将从索引中完全删除文件的内容。这意味着在提交时,文件将从提交中删除HEAD。(如果文件仅被添加到索引并且尚未被跟踪,则这是“无操作”。)

git reset -- <file>resets the contents of the file in the index to be the same as the head commit. This means that on commit no changeswill be committed to the file. This operation is not valid if there is no tracked version of the file in the HEADcommit.

git reset -- <file>将索引中文件的内容重置为与头部提交相同。这意味着在提交时不会向文件提交任何更改。如果HEAD提交中没有文件的跟踪版本,则此操作无效。