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

问题描述 投票:1回答:2

我有一些存储库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 git-flow
2个回答
0
投票

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

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

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


0
投票

Git不喜欢写一个历史记录,它无法追溯到当前存储库被init创建的时间。如果您考虑一下,这就是您在这里所做的事情:从国外某个地方获取重大历史记录,然后尝试将其拍入新的回购协议中,而该回购协议对您想要移植的历史一无所知在顶部。

最简单的方法是克隆存储库,签出要使用的所有分支和标签(如果只是主节点,则无需签出任何内容),然后将远程origin指向新的网址,然后推送。

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

这也应避免强行推动,最好避免。

© www.soinside.com 2019 - 2024. All rights reserved.