[英]Why behaviour of git fetch origin +refs/heads/master:refs/remotes/origin/mymaster and git fetch origin master:mymaster is different?
Why behaviour of 为什么行为
git fetch origin +refs/heads/master:refs/remotes/origin/mymaster
and 和
git fetch origin master:mymaster
is different? 是不同的?
In my observation in case of 在我看来
git fetch origin +refs/heads/master:refs/remotes/origin/mymaster
it was creating a remote-tracking branch "mymaster". 它正在创建一个远程跟踪分支“ mymaster”。
On the other case of 在另一种情况下
git fetch origin master:mymaster
it was creating a local branch "mymaster". 它正在创建本地分支“ mymaster”。
Well git fetch
will fast-forward your local reference, and create it if it doesn't exist. 好的git fetch
将快速转发您的本地引用,如果不存在则创建它。 So: 所以:
git fetch origin master:mymaster
creates a branch mymaster
locally if it doesn't exist and 如果不存在, mymaster
在本地创建分支mymaster
,然后
git fetch origin +refs/heads/master:refs/remotes/origin/mymaster
creates a branch remotes/origin/mymaster
locally if it doesn't exist. 如果不存在,则在本地创建一个分支remotes/origin/mymaster
。
The syntax being src:dst
, where src
is remote and dst
local. 语法为src:dst
,其中src
是远程的, dst
本地的。
Read the gitrevisions
manual page (run git help revisions
) and look for the revision specification " <refname>
". 阅读gitrevisions
手册页(运行git help revisions
)并查找修订规范“ <refname>
”。 Here's an excerpt from that bit of documentation: 这是该文档的摘录:
<refname>
, egmaster
,heads/master
,refs/heads/master
<refname>
,例如master
,heads/master
,refs/heads/master
A symbolic ref name. 符号引用名称。 Eg
master
typically means the commit object referenced byrefs/heads/master
. 例如master
通常是指refs/heads/master
引用的提交对象。 If you happen to have bothheads/master
andtags/master
, you can explicitly sayheads/master
to tell Git which one you mean. 如果您碰巧同时拥有heads/master
和tags/master
,则可以明确地说出heads/master
来告诉Git您是什么意思。 When ambiguous, a<refname>
is disambiguated by taking the first match in the following rules: 当模棱两可时,<refname>
将通过遵循以下规则中的第一个匹配项来消除歧义:
- If
$GIT_DIR/<refname>
exists, that is what you mean (this is usually useful only forHEAD
,FETCH_HEAD
,ORIG_HEAD
,MERGE_HEAD
andCHERRY_PICK_HEAD
); 如果$GIT_DIR/<refname>
存在,这就是您的意思(这通常仅对HEAD
,FETCH_HEAD
,ORIG_HEAD
,MERGE_HEAD
和CHERRY_PICK_HEAD
);- otherwise,
refs/<refname>
if it exists; 否则,refs/<refname>
如果存在);- otherwise,
refs/tags/<refname>
if it exists; 否则,使用refs/tags/<refname>
如果存在);- otherwise,
refs/heads/<refname>
if it exists; 否则,refs/heads/<refname>
如果存在);- otherwise,
refs/remotes/<refname>
if it exists; 否则,refs/remotes/<refname>
如果存在);- otherwise,
refs/remotes/<refname>/HEAD
if it exists. 否则,refs/remotes/<refname>/HEAD
如果存在)。
So what you observed in your experiments is that when you have used unadorned mybranch
as the target ref name, from the point of view of Git that was a relative ref name, and hence Git used the precedence rules to resolve it, and resolved it to refs/heads/mymaster
. 因此,您在实验中观察到的是,当您使用mybranch
作为目标引用名称时,从Git的角度来看,它是一个相对引用名称,因此Git使用优先规则对其进行解析,并将其解析为refs/heads/mymaster
。
When you used refs/remotes/origin/mymaster
, you supplied Git with the absolute ref name, so there was nothing to resolve and Git used it directly. 当您使用refs/remotes/origin/mymaster
,您为Git提供了绝对的引用名称,因此没有任何可解决的问题,Git直接使用了它。
A point of interest: it's perfectly OK to have a local branch containing a slash in its name, and it will still be relative when specified without that refs/...
anchor. 有趣的一点:拥有一个名称中包含斜杠的本地分支是完全可以的,并且在没有refs/...
锚的情况下指定时,它仍然是相对的。 That is, you can do git branch foo/bar
and when you will later call git log foo/bar
Git will use the rules above to resolve foo/bar
into an absolute ref name (and will supposedly end up with refs/heads/foo/bar
). 也就是说,您可以执行git branch foo/bar
,当您稍后调用git log foo/bar
Git将使用以上规则将foo/bar
解析为绝对引用名称(并且最终会以refs/heads/foo/bar
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.