简体   繁体   English

git checkout vs git checkout HEAD vs git checkout <CURRENT BRANCH> vs git checkout — <WORKING DIR>

[英]git checkout vs git checkout HEAD vs git checkout <CURRENT BRANCH> vs git checkout — <WORKING DIR>

I'm trying to determine the differences that exist among the following 4 commands. 我正在尝试确定以下4个命令之间存在的差异。

Assume that the current branch is master , and the current directory is the "working directory", ie, the one where .git is. 假设当前分支为master ,当前目录为“工作目录”,即.git所在的.git

git checkout

git checkout HEAD

git checkout master

git checkout -- .

As far as I can tell, the first two commands are completely equivalent , and are essentially no-op's (except for the fact that they both may produce some output); 据我所知,前两个命令是完全等效的 ,并且本质上是无操作的(除了它们都可能产生一些输出的事实之外); the third one is almost identical to the first two, except that it will produce, in addition to any other output the former produce, the line Already on 'master'. 第三个几乎与前两个相同,除了它除了会产生前一个产品的任何其他输出外,还会产生Already on 'master'.的行Already on 'master'. The last command, in contrast to all the other ones, will discard all the unstaged changes. 与所有其他命令相比,最后一个命令将丢弃所有未分段的更改。

Have I missed anything? 我错过了什么吗?

According to TFM , there are four forms of the git checkout command. 根据TFM的介绍git checkout命令有四种形式。 Your first two examples are one of them, and your other two examples are two more. 您的前两个示例是其中之一,另外两个示例是另外两个。

So to answer your question, you've missed the last form of git checkout : 因此,要回答您的问题,您已经错过了git checkout的最后一种形式:

git checkout -b <new branch name> <start point>

The first 3 are the same (and are not no-ops, if you did change some files they will get replaced by the ones in the tip of master). 前三个相同( 不是无操作,如果您更改了一些文件,它们将被主机提示中的文件替换)。 The 4th one checks out only the files in '.', ie, the current directory. 第四个检出“。”中的文件,即当前目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM