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 -- .
显然只会在当前目录(及其子目录)上运行,git reset --hard
将在完整的工作树上运行。
git checkout -- .
只会更新工作树并保留已暂存的文件,而git reset --hard
将索引和工作树与 HEAD 提交匹配。
与 refspec 一起使用时:
reset
将当前分支头设置为给定的提交(并匹配索引和工作树)checkout
将切换到该分支,当它们触及在当前分支和要签出的分支之间没有更改的文件时,本地更改保持不变这些答案很好。我想补充一点,如果您删除了已暂存但尚未提交的文件,那么checkout .
单独的 git 不会将已删除的文件带回工作区。一份git reset --hard
遗嘱。