本文介绍了“git rm --cached x” vs“git reset head - x”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但是> git rm --cached asd 和 git reset head - asd ?

解决方案

有三个地方,一个文件可以是 - 树,索引和工作副本。当你只是添加一个文件到一个文件夹,你将它添加到工作副本。



当你做一些像 git add file 您将其添加到索引。当你提交它时,你也可以将它添加到树中。



它可能会帮助你了解git reset中三个更常见的标志:


$ b

现在,当你做一些像 git reset HEAD 的东西时 - 你实际做的是 git reset HEAD --mixed ,它会将索引重置到开始添加文件/向索引添加修改之前的状态(通过 git add )在这种情况下,工作副本和索引(或分段)是同步的,但是您在重置后使HEAD和索引同步。


$ b $另一方面,从工作目录和索引中删除一个文件,当你提交时,文件也从树中删除。 git rm --cached 但是只从索引中删除文件并将其保存在工作副本中。这与 git add file 完全相反。在这种情况下,您使索引与HEAD和工作不同,其中HEAD具有先前承诺版本的文件,工作副本有las修改如果有任何或内容来自文件的HEAD,并且您从索引中删除了该文件。现在提交会同步索引和树,文件将被删除。


GitRef.org - Basic:

But what exactly is the difference between git rm --cached asd and git reset head -- asd?

解决方案

There are three places where a file, say, can be - the tree, the index and the working copy. When you just add a file to a folder, you are adding it to the working copy.

When you do something like git add file you add it to the index. And when you commit it, you add it to the tree as well.

It will probably help you to know the three more common flags in git reset:

Now, when you do something like git reset HEAD - what you are actually doing is git reset HEAD --mixed and it will "reset" the index to the state it was before you started adding files / adding modifications to the index ( via git add ) In this case, the working copy and the index ( or staging ) were in sync, but you made the HEAD and the index to be in sync after the reset.

git rm on the other hand removes a file from the working directory and the index and when you commit, the file is removed from the tree as well. git rm --cached however removes the file from index alone and keeps it in your working copy. This is the exact opposite of git add file In this case, you made index to be different from the HEAD and the working, in it that the HEAD has the previously committed version of the file, working copy had the las modification if any or content from HEAD of the file and you removed the file from the index. A commit now will sync the index and tree and the file will be removed.

这篇关于“git rm --cached x” vs“git reset head - x”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:17