"git checkout-" . vs git checkout [英] "git checkout --" . vs git checkout

查看:79
本文介绍了"git checkout-" . vs git checkout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是使用git checkout -- .来清除我的工作目录.我以为我在某处读到需要--以避免git认为您正在传递参数(或其他东西)

I always used git checkout -- . to clear my working directory. I thought I read somewhere that the -- was required to avoid git thinking you are passing parameters (or something)

现在,一位同事告诉我,我可以放下--,实际上,快速测试的效果完全相同.

Now a colleague told me I could drop the --, and indeed, a quick test did exactly the same.

这两个命令之间有什么区别吗?

Is there are any difference between those two commands?

PS:在这里问是因为git checkout -- . vs git checkout .很难用Google搜索...

PS: Asking here because git checkout -- . vs git checkout . is kind of hard to google...

推荐答案

我似乎还记得--是一种告诉Git将checkout之后的内容视为文件而不是分支的方法.假设您同时有一个文件和一个名为stuff的分支.那么下面的命令似乎是模棱两可的:

I seem to recall that the -- is a way to tell Git to treat what follows checkout as a file and not as a branch. Suppose that you had both a file and a branch called stuff. Then the following command would seem ambiguous:

git checkout stuff

因为不清楚是要签出文件还是分支.通过使用--,您明确告诉Git通过该名称/路径检出文件.因此,在这种情况下,以下命令允许检出一个分支和一个名为stuff的文件:

because it is not clear whether you are asking to checkout a file or a branch. By using -- you explicitly tell Git to checkout a file by that name/path. So in this case the following commands allow checking out a branch and a file called stuff:

git checkout stuff       # checkout the branch stuff
git checkout -- stuff    # checkout the file stuff

请注意,git checkout <name>实际上是用于分支的,但是Git语法很宽松,如果Git找不到分支,则它将查找文件.

Note that git checkout <name> is really meant for branches, but Git syntax is relaxed, and if Git can't find a branch, then it will look for a file.

密切相关:当文件为存在相同的名称

这篇关于"git checkout-" . vs git checkout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆