Git:合并两个不同的、独立的存储库

发布于 2024-10-24 17:30:53 字数 1079 浏览 3 评论 0 原文

存储库 A:从项目的 SVN 版本 r 迁移到 git:克隆了整个内容,包括所有 SVN 的历史记录、标签等。之后在 git 上进行了一些开发。

存储库 B:同一项目,但在修订版 r+small_number 时从 SVN 独立迁移。仅将最新的快照引入 git。后来有很多独立开发。

现在我将 A 合并到 B 中。想法是放弃 SVN,开发将在 GitHub 上项目存储库的 develop 分支中继续。我使用简单的合并来完成这项工作;值得庆幸的是,真正的冲突很少。开发主要是在不同的领域,尽管合并后有很多清理工作,与 git 无关。

但是:现在当我在 合并结果,我理解应该让我重新调整最后两次提交的基础,我看到了大约 300 多个提交的页面——自修订以来项目的完整历史记录SVN 中为 1。我中止了 rebase,因为担心搞砸更多(显然我是一个完全的 Git 新手)。

这是预期的结果吗?值得吗?如果没有,如何修复?

请注意,所有单元测试等都通过了,文件本身没问题,只是我不明白 git 元数据/历史记录发生了什么。

编辑:这就是我*的想法* 存储库现在如下所示:

          r         A
... o --- o --- ... o 
                     \ 
               B      \    
    o --- .... o ----  o --- ... o 
   r+small_number      C         HEAD

Repository A: migrated to git from a project's SVN at revision r: cloned the whole thing including all of SVN's history, tags, etc. A little development on git afterwards.

Repository B: the same project, but independently migrated from SVN at revision r+small_number. Only the latest snapshot was brought into git. Lots of independent development afterwards.

Now I merged A into B. The idea is that SVN will be discarded, development will continue in the develop branch of the project's repo on GitHub. I used simple merge to do the job; thankfully there were very few real conflicts. The development was mostly in different areas, though there was a lot of cleaning up after the merge, unrelated to git.

But: now when I do e.g. git rebase -i HEAD~2 on the merged result, which I understand should let me rebase the last two commits, I am greeted with a page of some 300+ commits -- the complete history of the project since revision 1 in SVN. I aborted the rebase for fear of messing up even more (obviously I'm a complete Git novice).

Is that outcome expected? Is it desirable? If not, how to fix it?

Note that all unit tests etc. pass, the files themselves are ok, only I don't understand what happened to git metadata/history.

EDIT: this is what I *think* the repository looks like now:

          r         A
... o --- o --- ... o 
                     \ 
               B      \    
    o --- .... o ----  o --- ... o 
   r+small_number      C         HEAD

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2024-10-31 17:30:53

我猜想发生这种行为是因为您试图通过合并提交进行变基。

对于以下答案,我假设您的历史记录如下所示,即存储库 A 和 B 是完全独立的:

          r         A
... o --- o --- ... o

o ... o
r'    B

您需要问自己要实现什么目标?因此,您希望有一个新分支 C,其中包含 A 和 B 中的更改。这里的优先级是什么?你想获得正确的历史吗?纠正 r' 丢失其 SVN 历史记录的事实?或者保持 A 和 B 的 git 历史记录不变很重要吗?

我的回答是假设你想实现前者。由于 A 和 B 都源自非常相似的 SVN 存储库版本,因此在合并共同历史记录之前为它们提供一个共同的 git 库可能是一个好主意。因此,理想情况下,在合并之前,您会遇到这种情况:

          r          A
... o --- o --- .... o
           \
            \
             o --- .... o
       r+small_number   B

目前,我不确定哪种方法是实现此目的的最佳方法,但您可以尝试执行 git rebase -p --onto r --root B< /代码>。

然后你可以git merge A和B并最终得到

          r          A     C
... o --- o --- .... o --- o
           \              /
            \            /
             o --- .... o
       r+small_number   B

C包含所有更改的历史记录。我可能会就此罢休;无需任何进一步的变基。

I guess this behaviour occurs because you are trying to rebase over a merge commit.

For the following answer, I'm assuming that your history looks like this, i.e. repositories A and B are completely independent:

          r         A
... o --- o --- ... o

o ... o
r'    B

You need to ask yourself what are you trying to achieve? So you want to have a new branch C containing both the changes in A and B. What are the priorities here? Do you want to achieve a proper history; correcting the fact that r' lost its SVN history? Or is it important to keep the git history of A and B unchanged?

My answer is going to assume you want to achieve the former. As both A and B descendet from very similar versions of the SVN repository, it might be a good idea to give them a common git base before merging the common history. So, ideally before merging you would have the situation:

          r          A
... o --- o --- .... o
           \
            \
             o --- .... o
       r+small_number   B

At the moment, I'm not sure which is the best way to achieve this, but you could try doing git rebase -p --onto r --root B.

Then you could just git merge A and B and end up with the history

          r          A     C
... o --- o --- .... o --- o
           \              /
            \            /
             o --- .... o
       r+small_number   B

where C contains all your changes. I would probably leave it at that; without any further rebasing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文