首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在使用单分支时,Git不能解析远程分支?

为什么在使用单分支时,Git不能解析远程分支?
EN

Stack Overflow用户
提问于 2019-03-26 01:47:17
回答 2查看 1.2K关注 0票数 5

因此,我们经常通过有效地克隆单支克隆来优化克隆.然而,我们随后无法获得更多的分支。从管道的角度看,有和没有单支的git克隆人有什么区别?以后怎样才能取下更多的分支呢?

标准克隆人:

代码语言:javascript
复制
$ git clone -b branch-name https://repo.url standard
$ cd standard
$ git checkout remote-branch
Branch 'remote-branch' set up to track remote branch 'remote-branch' from 'origin'.
Switched to a new branch 'remote-branch'

单支克隆人:

代码语言:javascript
复制
$ git clone -b branch-name --single-branch https://repo.url singlebranch
$ cd singlebranch
$ git checkout remote-branch
error: pathspec 'remote-branch' did not match any file(s) known to git

更新

下面是@AndrewMarshall的回答,您需要在配置中更新默认的fetch refspec。即使您可以在fetch中以黑客的方式删除右提交,但是如果您不首先修复配置,那么尝试的签出绝对会拒绝了解有关该分支的任何信息:

代码语言:javascript
复制
$ git fetch origin +refs/heads/remote-branch:refs/remotes/origin/remote-branch
From https://gerrit.magicleap.com/a/platform/mlmanifest
 * [new branch]      remote-branch -> origin/remote-branch

$ git checkout remote-branch 
error: pathspec 'remote-branch' did not match any file(s) known to git

$ git remote set-branches origin --add remote-branch
$ git checkout remote-branch 
Branch 'remote-branch' set up to track remote branch 'remote-branch' from 'origin'.
Switched to a new branch 'remote-branch'

注意,我们获取它,然后重新配置,然后签出。获取可以按任何顺序进行(尽管您必须传递参数(如果不是在配置中),但是签出是由配置设置的门控

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-26 02:12:58

--single-branch的工作方式是将远程的fetch属性设置为仅为单个分支名称,而不是glob:

代码语言:javascript
复制
$ git config --get-all remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master

所以让我们用git remote set-branches添加一个条目

代码语言:javascript
复制
$ git remote set-branches origin --add other-branch
$ git config --get-all remote.origin.fetch    
+refs/heads/master:refs/remotes/origin/master
+refs/heads/other-branch:refs/remotes/origin/other-branch

$ git fetch
From origin
 * [new branch]      other-branch        -> origin/other-branch

$ git checkout other-branch
Branch 'other-branch' set up to track remote branch 'other-branch' from 'origin'.
Switched to a new branch 'other-branch'

或者,将其设置为glob,以便获取所有分支(默认的非单分支行为)(请注意,引用*是为了避免shell展开;glob用于git,而不是shell):

代码语言:javascript
复制
git remote set-branches origin '*'
票数 12
EN

Stack Overflow用户

发布于 2022-04-30 13:22:25

非常简短的摘要:

  • 如果你用过“单支”
  • 你必须做这两件的事

$ git远程集-分支来源--添加其他分支 $ git提取

  • 然后你就可以

$ git结帐其他分行

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55348731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档