Git克隆-单分支不适用于sha/commit id? [英] Git clone --single-branch does not work for sha / commit ids?

查看:95
本文介绍了Git克隆-单分支不适用于sha/commit id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有效:

 git clone --branch='master' \
    --single-branch \
    git@bitbucket.org:teros/datavana.git 

但这不是:

commit='fda0b49f81d0b67ad8a1413eca129498b9eb61db'

git clone --branch="$commit" \
    --single-branch  \
    git@bitbucket.org:teros/datavana.git 

我得到的错误是:

Cloning into 'datavana'...
Warning: Permanently added the RSA host key for IP address 'xx.xxx.93.1' to the list of known hosts.
warning: Could not find remote branch fda0b49f81d0b67ad8a1413eca129498b9eb61db to clone.
fatal: Remote branch fda0b49f81d0b67ad8a1413eca129498b9eb61db not found in upstream origin

我肯定知道git commit id在远程中-因此是否有某些原因不起作用?有没有办法克隆单个提交(而不是按分支名称)?

I know for sure that the git commit id is in the remote - so is there some reason this won't work? Is there a way to clone a single commit (instead of by branch name)?

推荐答案

这是有意的,以便对从存储库中可以获取的内容进行一些控制,尤其是在单个对象数据库服务多个存储库的设置中.

This was intentional, to allow some control over what could be fetched from repos, especially in setups where a single object db serves multiple repos.

您可以通过在上游回购中设置uploadpack.allowanysha1inwant 来启用获取任意阴影,之后,您可以通过提供完整的哈希值从其中获取任意阴影,但是git clone没有针对任意refspec进行设置,您必须例如

You can enable fetching any arbitrary sha by setting uploadpack.allowanysha1inwant in the upstream repo, after which you'll be able to fetch arbitrary sha's from it by giving the full hash, but git clone isn't set up for arbitrary refspecs, you'll have to e.g.

git init .
git remote add origin git@bitbucket.org:teros/datavana.git
git fetch origin fda0b49f81d0b67ad8a1413eca129498b9eb61db:refs/heads/newbranch

无论如何,init和远程添加基本上都是克隆为您提供的所有额外功能.

where the init and remote add are basically everything extra the clone does for you anyway.

除了Git本身,我什么都不支持.

I don't know whether anything but Git itself supports this.

这篇关于Git克隆-单分支不适用于sha/commit id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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