简体   繁体   English

为什么git fetch origin + refs / heads / master:refs / remotes / origin / mymaster和git fetch origin master:mymaster的行为不同?

[英]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> , eg master , heads/master , refs/heads/master <refname> ,例如masterheads/masterrefs/heads/master

A symbolic ref name. 符号引用名称。 Eg master typically means the commit object referenced by refs/heads/master . 例如master通常是指refs/heads/master引用的提交对象。 If you happen to have both heads/master and tags/master , you can explicitly say heads/master to tell Git which one you mean. 如果您碰巧同时拥有heads/mastertags/master ,则可以明确地说出heads/master来告诉Git您是什么意思。 When ambiguous, a <refname> is disambiguated by taking the first match in the following rules: 当模棱两可时, <refname>将通过遵循以下规则中的第一个匹配项来消除歧义:

  1. If $GIT_DIR/<refname> exists, that is what you mean (this is usually useful only for HEAD , FETCH_HEAD , ORIG_HEAD , MERGE_HEAD and CHERRY_PICK_HEAD ); 如果$GIT_DIR/<refname>存在,这就是您的意思(这通常仅对HEADFETCH_HEADORIG_HEADMERGE_HEADCHERRY_PICK_HEAD );
  2. otherwise, refs/<refname> if it exists; 否则, refs/<refname>如果存在);
  3. otherwise, refs/tags/<refname> if it exists; 否则,使用refs/tags/<refname>如果存在);
  4. otherwise, refs/heads/<refname> if it exists; 否则, refs/heads/<refname>如果存在);
  5. otherwise, refs/remotes/<refname> if it exists; 否则, refs/remotes/<refname>如果存在);
  6. 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.

相关问题 Git 中的“refs/heads/master”是否与“refs/remotes/origin/master”相同? - Is "refs/heads/master" same as "refs/remotes/origin/master" in Git? git fetch不会更新.git / refs / remotes / origin / master - git fetch does not update .git/refs/remotes/origin/master 自制安装错误期间失败:git fetch origin master:refs/remotes/origin/master --tags --force - homebrew install error Failed during: git fetch origin master:refs/remotes/origin/master --tags --force 自制软件安装:失败期间:git 获取原始主机:refs/remotes/origin/master -n --depth=1 - Homebrew install: Failed during: git fetch origin master:refs/remotes/origin/master -n --depth=1 致命:refspec的远程部分不是.git / refs / heads / master中的有效名称:.git / refs / remotes / origin / master - fatal: remote part of refspec is not a valid name in .git/refs/heads/master:.git/refs/remotes/origin/master 什么是`git push origin master`?帮助git的refs,head和remotes - What is `git push origin master`? Help with git's refs, heads and remotes git push origin master:refs / heads / master这是做什么的 - git push origin master:refs/heads/master what does this do 在使用 @io_bazel_rules_docker 时运行 'git fetch origin refs/heads/*:refs/remotes/origin/* refs/tags/*:refs/tags/*' 时出错 - error running 'git fetch origin refs/heads/*:refs/remotes/origin/* refs/tags/*:refs/tags/*' while working with @io_bazel_rules_docker Git refs / remotes / origin / master不指向有效对象 - Git refs/remotes/origin/master does not point to a valid object Git:内部错误:refs / remotes / origin / master不是有效的打包引用 - Git: Internal error: refs/remotes/origin/master is not a valid packed reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM