简体   繁体   中英

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.

Assume that the current branch is master , and the current directory is the "working directory", ie, the one where .git is.

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'. 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. 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 -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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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