我有一个Git版本控制下的项目,我在服务器和本地计算机上工作。我原来有远程起源设置为我的本地计算机,但我现在想把它改为BitBucket。
在服务器上使用该命令
git remote set-url origin bitbucket_address
但是现在当我试图推动我的项目时,我得到了错误
! [remote rejected] master -> master (shallow update not allowed)
是什么导致了这种情况,我如何解决它?
我有一个Git版本控制下的项目,我在服务器和本地计算机上工作。我原来有远程起源设置为我的本地计算机,但我现在想把它改为BitBucket。
在服务器上使用该命令
git remote set-url origin bitbucket_address
但是现在当我试图推动我的项目时,我得到了错误
! [remote rejected] master -> master (shallow update not allowed)
是什么导致了这种情况,我如何解决它?
当前回答
似乎你已经使用了git clone——depth <number>来克隆你的本地版本。这将导致一个浅克隆。这种克隆的一个限制是您不能将它推入新的存储库。
你现在有两个选择:
如果你不在乎你丢失的历史,看看这个问题 如果你想保留完整的历史,请继续阅读:
你想保留你的历史,是吗?这意味着您必须对存储库进行非浅化。如果你已经移除或更换了旧的遥控器,那么你需要重新添加它:
git remote add old <path-to-old-remote>
之后,我们使用git fetch从旧的远程获取剩余的历史记录(正如这个答案所建议的那样)。
git fetch --unshallow old
现在您应该能够将数据推入新的远程存储库。
注意:在移除你的克隆后,你可以删除旧的遥控器。
其他回答
根据投票最多的答案,我创建了一个别名来自动化事情:
添加到你的.gitconfig:
[alias]
unshallow = !"git fetch --unshallow \"${1:-origin}\" # Unshallow from remote $1 (defaults to origin)"
用法:
Git unshallow #基于源远程的非浅当前分支 Git unshallow other-remote #非浅层当前分支从远程other-remote
如果你的回购是原点,而原始回购是上游:
git fetch --unshallow upstream
似乎你已经使用了git clone——depth <number>来克隆你的本地版本。这将导致一个浅克隆。这种克隆的一个限制是您不能将它推入新的存储库。
你现在有两个选择:
如果你不在乎你丢失的历史,看看这个问题 如果你想保留完整的历史,请继续阅读:
你想保留你的历史,是吗?这意味着您必须对存储库进行非浅化。如果你已经移除或更换了旧的遥控器,那么你需要重新添加它:
git remote add old <path-to-old-remote>
之后,我们使用git fetch从旧的远程获取剩余的历史记录(正如这个答案所建议的那样)。
git fetch --unshallow old
现在您应该能够将数据推入新的远程存储库。
注意:在移除你的克隆后,你可以删除旧的遥控器。
如果你想保持回购与你添加的新提交一样,那么另一个选择是:用一个交互式的rebase修改这个提交。
Start an interactive rebase including the first (root) commit with git rebase --interactive --root Change the pick of the initial commit(s) to edit and save & close the file. If you've cloned the repo with greater depth than 1, you may need to do the same for all of those commits. Or, alternatively, execute fixup for all of these during the interactive rebase. Convert this commit to a regular, unshallow commit with git commit --amend --no-edit This will also change the commit ID and add you as co-author to this initial commit. Don't forget to finish your rebase git rebase --continue
如果取回。unshallow不起作用。你们的分行一定有问题。在推它之前,用下面的命令修复它。
git filter-branch -- --all
只使用——unshallow不行,因为有安全方面的考虑。