繁体   English   中英

从旧的存储库中创建新的存储库并保存日志历史记录

[英]Creating new repository out of old one and saving the log history

我有一些存储库 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.

新的远程存储库是空的,没有任何文件。 它也只有主分支。 我究竟做错了什么?

编辑:我运行了以下命令:

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'

新的远程存储库是空的,没有任何文件。

我想它至少有一个提交,甚至是一个空的提交,这可以解释为什么推送失败。

尝试git push --force -u origin master并检查远程存储库历史记录反映您的本地存储库历史。

这假设“origin”设置为您创建的新的空远程存储库。
如果不:

git remote set-url origin /url/new/empty/remote/repo

关于error zeroPaddedFilemode消息,请检查您要添加的本地存储库是否有任何错误:

git fsck

如果是这样,请参阅“如何修复 Git 零填充文件模式警告”:重新创建本地存储库,使用导出/导入应该修复它,然后push --force应该可以工作。
另请参阅gitlab-org/gitlab-foss问题 22095作为此错误的说明。

Git 不喜欢编写无法追溯到当前存储库init时间的历史记录。 如果您考虑一下,这就是您在这里所做的事情:从外国某个地方获取一个大历史,并试图将它放在这个新的 repo 之上,它对您试图移植的历史一无所知在上面。

最简单的方法是克隆 repo,签出所有你想要使用的分支和标签(如果只是 master,你不需要签出任何东西)然后将远程origin重新指向新的 URL,并推。

git clone <OLD URL>
git checkout <branch>
...(repeat for all targeted branches)...
git fetch --tags
git remote rm origin
git remote add origin <new URL>
git push

这也应该防止需要强制推动,最好避免。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM