git浅克隆(克隆 - 深度)遗漏远程分支 [英] git shallow clone (clone --depth) misses remote branches

查看:767
本文介绍了git浅克隆(克隆 - 深度)遗漏远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

克隆远程仓库后,它不会通过-a选项显示任何远程分支。可能是什么问题呢?如何调试它?在这段代码中没有显示两个远程分支:

$ $ $ git clone --depth 1 git://git.savannah .gnu.org / pythonwebkit.git
$ cd pythonwebkit
$ git branch -a
* master
remotes / origin / HEAD - >原产地/主产地
遥控器/产地/主产地
$ git --version
git版本1.8.3.1

在另一台机器上尝试了相同的命令,它运行良好:

  $ git clone  - 深度1 git://git.savannah.gnu.org/pythonwebkit.git 
接收对象:100%(186886/186886),818.91 MiB | 3.44 MiB / s,完成。
$ cd pythonwebkit /
$ git branch -a
* master
remotes / origin / HEAD - >起源/大师
遥控器/原产地/ debian
遥控器/原产地/主控制器
遥控器/原产地/ python_codegen
$ git --version
git版本1.7.1

试过也克隆另一个回购,它效果很好。虽然我可以在这台机器上再次尝试它,但最好知道错在哪里。



任何建议或提示都会受到欢迎。

编辑:回答总结:由于git版本1.8.3.2需要一起使用--depth和--no-single-branch与以前一样的行为。这被认为是一个错误修复。

解决方案

行为是正确的,在最后一次修订后,master-branch是唯一的(因为这是主要远程的HEAD)远程分支:

  florianb $ git分支-a 
* master
遥控器/原点/ HEAD - >原产地/主产地
遥控器/产地/主产地



  florianb $ git branch -a 
* master
remotes / origin / HEAD - >起源/大师
遥控器/原产地/ debian
遥控器/原产地/母版
遥控器/原产地/ python_codegen






浅克隆



由于在技术文档中, git-clone --depth 20 repo code> [...]导致[s in]提交链的长度至多为20。因此,浅层克隆应该包含从分支机构的提示请求的提交深度。

另外, 另外 - git克隆 - -single-branch -option描述:


仅克隆通向单个分支尖端的历史记录,由 - 分支选项或主分支远程的 HEAD 指定。创建使用 - 深度选项的浅层克隆,这是缺省值,除非给出 - no-single-branch 以获取所有分行提示附近的历史记录。


因此,浅克隆深度选项)获取 一个分支(在您的请求中




不幸的是,两个选项( - depth - 单分支)过去一直存在问题,使用浅层克隆会引发未解决的问题(正如您可以在上面发布的链接中看到的那样),这是由给定的历史改写引起的。这在特殊情况下总体上会导致一些复杂的行为。


After cloning a remote repository it does not show any remote branch by -a option. What could be the problem? How to debug it? In this snippet two of the remote branches are not shown:

$ git clone --depth 1 git://git.savannah.gnu.org/pythonwebkit.git
$ cd pythonwebkit
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
$ git --version
git version 1.8.3.1

Tried the same command on another machine, it works well:

$ git clone --depth 1 git://git.savannah.gnu.org/pythonwebkit.git
Receiving objects: 100% (186886/186886), 818.91 MiB | 3.44 MiB/s, done.
$ cd pythonwebkit/
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/debian
  remotes/origin/master
  remotes/origin/python_codegen
$ git --version
git version 1.7.1

Tried also cloning another repo, it works well. Though I can try it on this machine again, but it would be better to know what's wrong.

Any suggestions or hints will be more than welcome.

Edit: Answer summary: Since git version 1.8.3.2 the "--depth" and "--no-single-branch" need to be used together to get the same behavior as before. This is deemed a bug fix.

解决方案

The behavior is correct, after the last revision the master-branch is (since this is the primary remote's HEAD) the only remote-branch in the repository:

florianb$ git branch -a
        * master
          remotes/origin/HEAD -> origin/master
          remotes/origin/master

The full clone offers new (all) branches:

florianb$ git branch -a
        * master
          remotes/origin/HEAD -> origin/master
          remotes/origin/debian
          remotes/origin/master
          remotes/origin/python_codegen


Shallow clones

Due to the shallow-description in the technical documentation, a "git-clone --depth 20 repo [...] result[s in] commit chains with a length of at most 20." A shallow clone therefore should contain the requested depth of commits, from the tip of a branch.

As - in addition - the documentation of git clone for the --single-branch-option describes:

"Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote's HEAD points at. When creating a shallow clone with the --depth option, this is the default, unless --no-single-branch is given to fetch the histories near the tips of all branches."

Therefore a shallow clone (with the depth-option) only fetches only one single branch (at your requested depth).


Unfortunately both options (--depth and --single-branch) have been faulty in the past and the use of shallow clones implicits unresolved problems (as you can read in the link I posted above), which is caused by the given history-rewrite. This leads in overall to somewhat complicated behavior in special cases.

这篇关于git浅克隆(克隆 - 深度)遗漏远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆