浅层更新不允许(git > 1.9)

6

有很多答案表明 git 1.9 移除了浅克隆的限制。然而,我正在使用2.6.1版本,仍然存在以下基本问题:

首先,在某个地方创建一个空的仓库:

cd /tmp
mkdir target
cd target
git init

然后,我浅克隆了一些仓库,并将上述仓库添加为远程仓库:
cd /tmp
git clone --depth 1 git@github.com:muennich/urxvt-perls.git
cd urxvt-perls
git remote add target /tmp/target

最后,我将此存储库推送到远程:

git push target master

但是我收到了这个:
! [remote rejected] master -> master (shallow update not allowed)
error: failed to push some refs to '/tmp/target'

我这里缺少什么?


如果您对GitLab允许此操作感兴趣,请查看https://gitlab.com/gitlab-org/gitlab-ce/issues/3033。 - memeplex
4个回答

7

我在回答自己的问题。

我尝试通过将urxvt-perls添加为target的远程仓库,然后从那里获取来解决问题。但由于同样的原因而失败,但让我更接近解决方案。根据git-fetch手册:

  --update-shallow
       By default when fetching from a shallow repository, git fetch
       refuses refs that require updating .git/shallow. This option
       updates .git/shallow and accept such refs.

现在,使用此选项允许进行浅层获取。因此,以前的问题变成了:是否可以在推送时指定--update-shallow行为?好吧,有一个选项:

receive.shallowupdate
    If set to true, .git/shallow can be updated when new refs require
    new shallow roots. Otherwise those refs are rejected.

我仍在尝试将此设置在GitHub等平台上。


那么,你现在在 GitHub 或 GitLab 上成功了吗? - Tony
不,我之前在 GitLab 的问题跟踪器中提出了一个问题,但似乎没有人真正关心。 - memeplex
我也很想知道Gerrit是否支持这个。 - bam
值得一提的是,GitHub 的跟踪器链接为 https://github.community/t/set-receive-shallowupdate-on-to-allow-pushing-from-shallow-clones/2424,而 GitLab 的跟踪器链接为 https://gitlab.com/gitlab-org/gitlab-foss/-/issues/3033。 - Mingye Wang

5
git fetch --unshallow

git push target master -f

2
使用 git merge --squash
如果你的远程仓库是浅层的,但你想要合并它,可以通过压缩这个 合并为单个提交 来避免复制一系列被浅层引用隐藏的提交历史。

0

在 Linux 软件仓库服务器上... 这个

git config --local --add receive.shallowUpdate true

导致这个被添加到仓库配置文件中。

[receive]
    shallowUpdate = true

如果您能将此添加到存储库配置文件中,那就太好了。


如果我使用Github或Gitlab,如何添加此配置? - Tony

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接