首页 > 解决方案 > 将浅回购转换为普通回购

问题描述

我已经“浅化”了一个回购:

FIRST_COMMIT="bf450342272a94117d78eae34a140a2a39359dad"
git rev-parse ${FIRST_COMMIT} > .git/shallow
git fsck --unreachable
git gc --prune=now

现在我尝试推动:

! [remote rejected] develop -> develop (shallow update not allowed)

我知道这个限制是由于回购很浅。

如何将浅回购转换为普通回购?

我不在乎失去旧的历史。其实我丢掉旧的历史

为了澄清这一点:

编辑

简单地删除.git/shallow文件不起作用:

» git push -f --set-upstream myorigin develop
error: Could not read d18d4a247bebd32a3b57b2c0e5f9c28749083211
fatal: revision walk setup failed
error: remote unpack failed: eof before pack header was fully read
error: failed to push some refs to 'git@somehost:repos/somerepo.git'

编辑2

试图通过以下方式来浅显fetch

git fetch --unshallow

仍然留下一个grafted回购:

commit bf450342272a94117d78eae34a140a2a39359dad (grafted)
Author: The author
Date:   Thu Nov 29 16:55:05 2018 +0100

    Chages by pre-commit hook (!?)

标签: gitshallow-clone

解决方案


“如何将 Git 浅克隆转换为完整克隆”

以下命令(git 版本 1.8.3)会将浅克隆转换为常规克隆:

git fetch --unshallow

然后,访问原点的所有分支(感谢评论中的@Peter)

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

推荐阅读