我有一个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)
是什么导致了这种情况,我如何解决它?
当前回答
如果你想推动新的回购,你可以试试这个:
首先从当前的repo中删除旧的git文件夹,sudo rm -rf .git 然后重新初始化git git init 然后添加新的远程回购 Git远程添加原点your-new-repo 然后推它。
其他回答
如果你想保持回购与你添加的新提交一样,那么另一个选择是:用一个交互式的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
似乎你已经使用了git clone——depth <number>来克隆你的本地版本。这将导致一个浅克隆。这种克隆的一个限制是您不能将它推入新的存储库。
你现在有两个选择:
如果你不在乎你丢失的历史,看看这个问题 如果你想保留完整的历史,请继续阅读:
你想保留你的历史,是吗?这意味着您必须对存储库进行非浅化。如果你已经移除或更换了旧的遥控器,那么你需要重新添加它:
git remote add old <path-to-old-remote>
之后,我们使用git fetch从旧的远程获取剩余的历史记录(正如这个答案所建议的那样)。
git fetch --unshallow old
现在您应该能够将数据推入新的远程存储库。
注意:在移除你的克隆后,你可以删除旧的遥控器。
如果是bitbucket管道
这可能是由于提交深度有限(默认50提交)
你可以增加限制
clone:
depth: 500 # include the last five hundred commits
pipelines:
default:
- step:
name: Cloning
script:
- echo "Clone all the things!"
注:使用深度:满为不限
如果你的回购是原点,而原始回购是上游:
git fetch --unshallow upstream
只需删除/.git/shallow中的shallow文件
现在应该可以了。