Git 中的“refs/heads/master”是否与“refs/remotes/origin/master”相同?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7541040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is "refs/heads/master" same as "refs/remotes/origin/master" in Git?
提问by Tower
The question is simple: is refs/heads/master
the same thing as refs/remotes/origin/master
? If it is not in some cases, how can I know when it is not and what it is then?
问题很简单:refs/heads/master
与refs/remotes/origin/master
? 如果在某些情况下不是,我怎么知道什么时候不是,然后是什么?
回答by Ben Hymanson
They are two different symbolic names that can point to different things. refs/heads/master
is a branch in your working copy named master
. Frequently that is a tracking branch of refs/remotes/origin/master
because origin
is the default name for the remote created by git clone
and its primary branch is usually also named master
.
它们是两个不同的符号名称,可以指向不同的事物。 refs/heads/master
是工作副本中名为master
. 通常这是一个跟踪分支,refs/remotes/origin/master
因为它origin
是远程创建的默认名称git clone
,其主要分支通常也命名为master
。
You can see the difference between them with git rev-list refs/heads/master..refs/remotes/origin/master
which will be empty if they are the same and will otherwise list the commits between them.
您可以看到它们之间的区别,git rev-list refs/heads/master..refs/remotes/origin/master
如果它们相同,它将为空,否则将列出它们之间的提交。
回答by Mark Longair
The key difference to understand is that the branches under refs/heads/
are branches that, when you have one checked out, you can advance by creating new commits. Those under refs/remotes/
, however, are so-called "remote-tracking branches" - these refs just point to the commit that a remote repository was at the last time you did a git fetch <name-of-remote>
, or a successful git push
to the corresponding branch in that remote repository. (I wrote a blog post that talks about this difference at some length here.)
要理解的主要区别在于,下面的分支refs/heads/
是分支,当您签出一个分支时,您可以通过创建新提交来推进。refs/remotes/
但是,在 下的那些是所谓的“远程跟踪分支” - 这些引用仅指向远程存储库在您上次执行git fetch <name-of-remote>
或 成功git push
时对该远程存储库中的相应分支进行的提交。(我写了一篇博客文章,在这里详细讨论了这种差异。)