git rm --cached file vs git reset file

折月煮酒 提交于 2019-11-28 15:43:43

问题


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

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?


回答1:


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 HEAD commit. (If the file was only added to the index and not yet tracked this is a "no-op".)

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 changes will be committed to the file. This operation is not valid if there is no tracked version of the file in the HEAD commit.



来源:https://stackoverflow.com/questions/12661306/git-rm-cached-file-vs-git-reset-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!