我有一个Git版本控制下的项目,我在服务器和本地计算机上工作。我原来有远程起源设置为我的本地计算机,但我现在想把它改为BitBucket。

在服务器上使用该命令

git remote set-url origin bitbucket_address

但是现在当我试图推动我的项目时,我得到了错误

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

是什么导致了这种情况,我如何解决它?


当前回答

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

添加到你的.gitconfig:

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

用法:

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

其他回答

为了简单地解决这个问题,如果您不关心远程现有的更改,那么按照以下方法进行。

从存储库中删除本地的.git文件夹。 输入git init。 再次添加远程git remote Add origin <REMOTE_URL>。 通过git branch -M main设置主分支。 推送你的更改,然后git推送——set-upstream origin main。

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

git filter-branch -- --all

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

如果你想保持回购与你添加的新提交一样,那么另一个选择是:用一个交互式的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

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

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

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

现在应该可以了。