【问题标题】:Shallow update not allowed (git > 1.9)不允许进行浅层更新(git > 1.9)
【发布时间】:2016-01-10 04:48:55
【问题描述】:

有很多答案表明 git 1.9 消除了浅克隆的限制。尽管如此,我使用的是 2.6.1,但仍然存在以下基本问题:

首先,我在某处创建了一个空仓库:

cd /tmp
mkdir target
cd target
git init

然后,我浅克隆一些 repo 并将上述 repo 添加为远程:

cd /tmp
git clone --depth 1 git@github.com:muennich/urxvt-perls.git
cd urxvt-perls
git remote add target /tmp/target

最后,我将这个 repo 推送到远程:

git push target master

然后我得到:

! [remote rejected] master -> master (shallow update not allowed)
error: failed to push some refs to '/tmp/target'

我在这里错过了什么?

【问题讨论】:

标签: git


【解决方案1】:

我正在回答我自己的问题。

我尝试反过来添加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 等中进行设置。

【讨论】:

【解决方案2】:

使用git merge --squash

如果您的遥控器很浅并且您想从中合并,请压缩 merge into a single commit 而无需复制提交历史记录(浅 refs 隐藏)。

【讨论】:

    【解决方案3】:

    在 Linux 存储库服务器上... 这个

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

    导致它被添加到 repo 配置文件中。

    [receive]
        shallowUpdate = true
    

    所以也许你可以将它添加到 repo 配置文件中。

    【讨论】:

    • 如果我使用 github 或 Gitlab,如何添加这个配置?
    【解决方案4】:
    git fetch --unshallow
    
    git push target master -f
    

    【讨论】:

      猜你喜欢
      • 2015-05-13
      • 2014-05-05
      • 2017-04-25
      • 1970-01-01
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      相关资源
      最近更新 更多