git中 git checkout -- file 与 git reset -- file 试验

本文验证 git checkout -- file   与  git reset -- file 命令的具体作用区域。

个人认为 git checkout -- file 是将暂存区的内容恢复到工作区;git reset -- file 是将仓库的内容恢复到暂存区

网上找个了图,觉得不错,展示下

git中 git checkout -- file 与 git reset -- file 试验

 

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

上图中我有疑问,个人认为应该不是直接从仓库还原到了工作,而应该还是从暂时存区还原到了工作,只不过暂存区的dev.txt已经提交了,所以不显示,但文件仍然存在。

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验

git中 git checkout -- file 与 git reset -- file 试验