据我了解,git checkout
是关于移动 head
.
例如,git checkout <commit id>
就是移动head
到 <commit id>
, git checkout <branch_name>
就是移动head
到 <branch_name>
.
然而,git checkout .
是丢弃未暂存的更改。 head
似乎没有任何业务.
所以我不明白为什么git
使用相同的关键字 checkout
做两件完全没有关系的事情。或者 git checkout .
仍然基于 head
工作?
最佳答案
如您所见,checkout
命令重载意味着两个不同的东西。我想git help checkout
不过,这很清楚:
git-checkout - Switch branches or restore working tree files
命令有多种形式,您要问的是:
git checkout [<tree-ish>] [--] <pathspec>...
在你的例子中是 <tree-ish>
参数被省略,--
分隔选项和文件名的参数被省略,<pathspec>
是.
(即当前目录)。该命令形式记录为:
Overwrite paths in the working tree by replacing with the contents in the index or in the
<tree-ish>
(most often a commit).
因为您没有指定 <tree-ish>
参数,.
中文件的内容被索引中的内容替换。这意味着放弃 .
中的任何更改尚未添加到索引中。
您可以将其视为“从存储库中 check out 这些文件”,这可以表示来自提交,也可以来自索引(可能包含已暂存但尚未提交的更改)。
关于git - 我们怎么理解git checkout [点],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52401478/