我有一个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 然后推它。

其他回答

根据投票最多的答案,我创建了一个别名来自动化事情:

添加到你的.gitconfig:

[alias]
    unshallow = !"git fetch --unshallow \"${1:-origin}\" # Unshallow from remote $1 (defaults to origin)"

用法:

Git unshallow #基于源远程的非浅当前分支 Git unshallow other-remote #非浅层当前分支从远程other-remote

如果你想推动新的回购,你可以试试这个:

首先从当前的repo中删除旧的git文件夹,sudo rm -rf .git 然后重新初始化git git init 然后添加新的远程回购 Git远程添加原点your-new-repo 然后推它。

如果是bitbucket管道

这可能是由于提交深度有限(默认50提交)

你可以增加限制

clone:
  depth: 500       # include the last five hundred commits
  
pipelines:
  default:
    - step:
        name: Cloning
        script:
          - echo "Clone all the things!"

注:使用深度:满为不限

只需删除/.git/shallow中的shallow文件

现在应该可以了。

如果取回。unshallow不起作用。你们的分行一定有问题。在推它之前,用下面的命令修复它。

git filter-branch -- --all

只使用——unshallow不行,因为有安全方面的考虑。