问题描述
为什么git允许我重置文件?我认为我理解 reset
,因为它正在移动HEAD ......显然我错了。
所以, git reset sha file
好像和 git checkout sha file
一样,除了我看到文件
在索引和工作目录中。
这对我没有意义。有人可以解释一下这个区别吗?
git reset
- soft
, - hard
和 - 混合
(和 - 保持
和 - 合并
)
- 混合
是默认值,当您执行 git reset sha file
您正在做 mixed
重置:
就像上面说的那样,这种情况下的重置根本不会碰到你的工作树,只有索引中的版本重置为沙中的版本。
git checkout
另一方面:
因此,当你执行 git checkout
时,你将丢失文件中的更改,并且它将被替换为sha中文件版本中的任何内容,而当你执行混合重置,只有您的索引将被重置,您的工作目录仍然会有变化,您可以稍后再次根据需要进行更改。
Why is it that git allows me to reset a file? I thought I understood reset
, in the sense that it was moving the HEAD ... clearly I was wrong.
So, git reset sha file
seems to do the same as git checkout sha file
, with the exception that I see file
in the index and in the working directory.
It doesn't make sense to me. Can someone please explain the difference?
git reset
has very important flags of --soft
, --hard
and --mixed
( and --keep
and --merge
)
http://git-scm.com/docs/git-reset
--mixed
is the default and when you do git reset sha file
you are doing mixed
reset whereby:
Like it says above, the reset in this case would not touch your working tree at all and only the version in the index is reset to the one in the sha.
git checkout
on the other hand:
So when you do git checkout
you will lose the changes in the file and it will be replaced with whatever was there in the version of file in sha, whereas when you do the mixed reset, only your index will be reset and your working directory will still have the changes which you can later stage again as needed.
这篇关于git reset文件和git checkout文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!