Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

Git checkout with dot

What difference between next git commands:

git  checkout branch
git  checkout branch .
git  checkout  .  #<-- used at the branch

Why when I checkout different branches into different folders with first one I missed some files.
But when I am using second command, everything is ok?

question from:https://stackoverflow.com/questions/14460595/git-checkout-with-dot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

git checkout(1) does very different things whether given path specifier or not.

  1. With branch specifier only (git checkout branch) it will switch current working directory to specified branch, keeping local changes if possible and failing otherwise. If you already are on branch, it will do nothing at all. It only modifies files in the working directory that differ between HEAD and branch and fails if any of them has local modifications (indexed or not).
  2. With path specifier it will overwrite the all matching files (all files match .) with specified content:
    1. With path specifier only (git checkout .) it writes content from index. That it is undoes unstaged local modification. To undo staged modifications, use git reset with path specifier.
    2. With both branch and path specifiers (git checkout branch .) it writes content in specified revision. It will not modify where HEAD points, so if branch is different from HEAD, there will be unstaged changes afterwards.

Note, that the man page distinguishes additional cases for use of the -b/--branch option and -p/--patch option, but those are mostly straightforward extensions of the above cases.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...