git reset --hard HEAD和git checkout之间有区别吗? [英] Is there a difference between git reset --hard HEAD and git checkout .?
问题描述
如果我对工作树进行了更改并且尚未提交,并且我想恢复所做的更改,那么
<$ p $ git reset --hard HEAD
和
git checkout。
?
git reset --hard code>将在完整的工作树上运行。
git checkout - 。
工作树并保留已经登台的文件,而 git reset --hard
将使索引和工作树与HEAD提交匹配。
与refspec一起使用时:
-
reset
会设置当前分支头到给定的提交(并匹配索引和工作树)
-
checkout
将切换到该分支,使本地更改保持原样,当他们触摸当前分支和要检出的分支之间没有变化的文件时
If I make changes to the working tree and have not yet committed, and I would like to revert the changes I have made, is there a difference between
git reset --hard HEAD
and
git checkout .
?
解决方案 git checkout -- .
will obviously only work on the current directory (and subdirectories thereof), git reset --hard
will operate on the complete working tree.
git checkout -- .
will only update the working tree and leave already staged files as is, whereas git reset --hard
will match index and working tree with the HEAD commit.
when used with a refspec:
reset
will set the current branch head to the given commit (and matches index and working tree)
checkout
will switch to that branch, leaving local changes intact, when they touch files which did not change between the current branch and the branch to be checked out
这篇关于git reset --hard HEAD和git checkout之间有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!