简体   繁体   English

git 分支名称本地与远程跟踪

[英]git branch names local vs remote tracking

I use git 1.8.3.2.我使用 git 1.8.3.2。

I use a bare "w1.git" repository to test git related things.我使用一个裸的“w1.git”存储库来测试与 git 相关的东西。

I did the following我做了以下

 git clone -- file:///home/rohloff/git/w1.git w1_clone

So now I have got the following branches (leaving out SHA1 and commit messages):所以现在我有以下分支(不包括 SHA1 和提交消息):

 git branch -avv

 master                   [origin/master]
 remotes/origin/HEAD      -> origin/master
 remotes/origin/master

So now I did所以现在我做到了

 git branch origin/master

and to my complete surprise that works ?!令我惊讶的是它有效吗?!

I now have got我现在有

git branch -avv

master                 [remotes/origin/master]
origin/master
remotes/origin/HEAD    -> origin/master
remotes/origin/master

Note how "master" now cleverly points to "remotes/origin/master".请注意“master”现在如何巧妙地指向“remotes/origin/master”。

But if I try to now create a topic branch with但是如果我现在尝试创建一个主题分支

git branch topic origin/master

I get (not surprisingly)我得到(毫不奇怪)

Warning: refname 'origin/master' is ambiguous.

So I am wondering:所以我想知道:

  • Is there any way to tell git to forbid the creation of "ambiguous" branches ?有没有办法告诉 git 禁止创建“模棱两可”的分支? Or is it simply my responsibilty to avoid creating such ambiguously named branches ?或者仅仅是我的职责是避免创建这种名称模糊的分支?
  • With the "git branch topic" above: Is there any way to clearly specify which branch I mean ?使用上面的“git branch 主题”:有没有办法明确指定我的意思是哪个分支?

EDIT : It turns out the following is also allowed:编辑:事实证明以下也是允许的:

 git branch origin/master
 git branch remotes/origin/master
 git branch refs/remotes/origin/master

After these three commands it seems there is no way at all anymore to refer to "master" from the "origin" remote repository...在这三个命令之后,似乎再也没有办法从“原始”远程存储库中引用“master”了……

EDIT : It turns out this problem is right now (15 Feb 2014) discussed on the git developer mailing list.编辑:事实证明这个问题现在(2014 年 2 月 15 日)在 git 开发人员邮件列表上讨论过。 see

https://marc.info/?t=139237924400005&r=1&w=2 https://marc.info/?t=139237924400005&r=1&w=2

The proposal is to forbid something like this as long as someone does not use "-f".建议是禁止这样的事情,只要有人不使用“-f”。

  • I don't believe there is a built-in way to prevent creation of ambiguous branches.我不相信有一种内置的方法可以防止创建不明确的分支。 And even if there was such an option to git branch , if you create a local branch origin/foo when there's no remotes/origin/foo that's something that might change over time.即使git branch有这样的选项,如果您在没有 remotes/origin/foo 的情况下创建本地分支 origin/foo ,这可能会随着时间的推移而改变。
  • Yes, you can specify the fully-qualified names, ie refs/heads/origin/master and refs/remotes/origin/master.是的,您可以指定完全限定的名称,即 refs/heads/origin/master 和 refs/remotes/origin/master。 In fact, you can drop the initial "refs/" as eg heads/origin/master is unambiguous.事实上,您可以删除初始的“refs/”,因为例如 head/origin/master 是明确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 VS Code 中使用远程跟踪创建本地 git 分支 - How to create local git branch with remote tracking in VS Code GIT:删除没有本地跟踪分支的远程分支 - GIT: remove remote branches with no local tracking branch “ git fetch”上的本地分支与远程分支 - Local branch vs remote branch on “git fetch” Git:Sane分支概述(本地[跟踪],远程(跟踪/陈旧/新)) - Git: Sane branch overview (local [tracking], remote (tracking/stale/new)) 它们的名称是否相同:本地跟踪分支,相应的远程跟踪分支以及正在跟踪的相应远程分支? - Are their names the same: a local-tracking branch, the corresponding remote-tracking branch, and the corresponding remote branch being tracked? git-将本地分支推送到父级的远程跟踪分支 - git - Pushing a local branch to the remote tracking branch of a parent 'git checkout'未创建本地分支以匹配远程跟踪分支 - 'git checkout' is not creating local branch to match remote tracking branch 本地分支和远程跟踪分支之间的git diff - git diff between local branch and remote tracking branch 如何判断哪个远程svn分支是本地git分支跟踪? - How to tell which remote svn branch is a local git branch tracking? Git 从本地分支推送到远程跟踪分支 - Git Pushing from a local branch to a remote tracking branch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM