我有一些存储库X。我想创建一个新的空存储库,其中包含X的所有文件以及提交历史记录。 我已经远程创建了一个新的存储库。我克隆了旧的存储库X,并运行了以下命令(我使用gitflow):
git flow init
git remote set-url origin $URL
git remote -u # Just to check
git push -u origin master
最后一条命令失败,并出现以下错误:
To $URL
! [rejected] master -> master (fetch first)
error: failed to push some refs to '$URL'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
新的远程存储库为空,没有任何文件。它还只有master分支。 我在做什么错了?
编辑:我运行了以下命令:
git push --force -u origin master
结果:
Counting objects: 3751, done.
Delta compression using up to 36 threads.
Compressing objects: 100% (1131/1131), done.
Writing objects: 100% (3751/3751), 577.15 KiB | 322 KiB/s, done.
Total 3751 (delta 2615), reused 3727 (delta 2605)
error: unpack failed: error zeroPaddedFilemode: object a8025c7657985de77312ba1eea3dd926d50eae2f: mode starts with '0'
fatal: Unpack error, check server log
To $URL
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to '$URL'
答案 0 :(得分:1)
新的远程存储库为空,没有任何文件。
我想它至少有一个提交,甚至有一个空提交,这可以解释为什么推送失败。
尝试git push --force -u origin master
并检查远程存储库历史记录以反映您的本地存储库。
这假定“ origin”已设置为您创建的新的空远程存储库。
如果没有:
git remote set-url origin /url/new/empty/remote/repo
关于error zeroPaddedFilemode
消息,请检查您要添加的本地存储库是否有任何错误:
git fsck
如果是这样,请参阅“ How to fix Git zero-padded file modes warning”:重新创建本地存储库,使用导出/导入功能可以修复它,然后push --force
应该可以使用。
另请参见gitlab-org/gitlab-foss
issue 22095作为此错误的说明。
答案 1 :(得分:0)
Git不喜欢写一个历史记录,它不能追溯到init
版本的当前存储库。如果您考虑一下,这就是您在这里所做的事情:从国外某个地方获取重大历史记录,然后尝试将其拍入新的回购协议中,而该回购协议对您想要移植的历史一无所知在顶部。
最简单的方法是克隆存储库,签出要使用的所有分支和标签(如果只是主节点,则不需要签出任何内容),然后重新指向远程{{1 }}到新网址,然后推送。
origin
这也应避免需要强行推动,最好避免。