2

Related but not quite what I am looking for merge-two-branches-what-direction.

Situation:

I have inherited an interesting problem. So we have a rails application that houses the code for a number of websites. Before I came to work here they branched the master branch to develop a new website. That's great but it was never merged back into master, and changes from master were not merged into the branch to keep it up to date.

Now master has 2 new websites and almost a third done while this branch has the one it was branched for and a new one that was similar enough to it that development was made simpler by doing it in that branch (like min saving of 100 hours).

Also they use the same database-structure and authentication systems which is really important for keeping track of our customers. Which is why I would like to merge them so I don't have to make the same changes to each code base when we change something in the database ect...

Problem:

My problem is that Now I don't know what to do with this branch. I want work being done out of the master branch with the occasional break off for a new feature that's rolled back in, but that's not whats happened. Its almost like we have 2 master branchs now because the code bases have grown so far apart.

I have tried merging the master into the other branch but that resulted in chaos, which we can't afford since there is development going on in both branches. So then I created a local branch and tried to merge the two into it. But after struggling with it for a couple days now and seemingly getting all the conflicts merged, only to have it fail my unit-tests and normal testing.

Plea for help:(question)

I am starting to think its impossible to merge the two since they are almost separate projects at this point (merging them involved adding or changing something like 430 files)

In short I guess my question is this: What do I do with the branches now?

(This is the first time as a developer that I have been in-charge of the source control and overall project management. So really at a loss here.)

p.s. sorry for the wall of text,

4

2 回答 2

4

首先,叉子没问题!如果您有两个分歧的分支,那么分开考虑它们可能是值得的。如果每个核心代码都有很大的改进,我只会真正尝试将它们合并回来,彼此分享会很好。否则,叉子通常很有用。

话虽如此,让我们假设您将努力合并它们。

首先,我会决定哪个分支实际上是你的主分支。当然,一个称为 master,但出于此合并的目的,您应该决定哪个分支更共享,并且如果历史记录发生变化会影响更多人。通常这确实是 master 分支,但如果没有其他人有 master 的副本,您可以选择看起来更容易的任何一个。

好的,现在你有了一个“master”分支,你应该努力不打扰那个 master 分支的历史。我们将调用另一个分支tf(用于完全分叉)。无论是来自添加到分支顶部的大型合并提交,还是来自tf. 这是我首先要做的:

  • 创建存储库的完整备份! <-- 如有疑问,请务必这样做。

试用合并

git checkout tf;
git branch tf_merging;
git checkout tf_merging;

git merge master; 检查冲突的程度。查看这些是否是重复修复(在这种情况下可以消除提交)或并行修复的冲突 // 如果您认为无法使用合并,请放弃此分支:

git checkout tf;

交互式变基

git checkout tf;
git branch tf_rebase;

git rebase -i master;// 交互式变基。使用合并尝试中的列表,尝试消除重复提交以防止。另请查看重新排列 tf 的提交是否会提供更好的合并候选者。
// 如果冲突太多:

git rebase --abort

// 仅尝试在 rebase 开始后执行几个 git rebase --continue 循环,最多可能是 7-10 次,否则您可能会过度处理冲突并最终导致一团糟。

最终的解决方案

如果你无法通过 git 实现你想要的解决方案,还有一个替代方案,那就是从非主分支中挑选你特别想保留的特性tf,并丢弃非必需项。例如,如果添加了一个tf在 master 中不存在的库,则将该库和其他有用的功能放在一边,以添加一个明确的 master 提交,以创建一个类似的分支tf,并且具有相同的功能,但是实际上是对最有用/核心功能更改的重新实现,并跳过了许多非必要的提交。tf本质上,您在核心 master 的一个分支之上杀死并重新实现它的最佳部分,以允许重新开始共享开发。

于 2012-08-28T15:32:35.447 回答
1

Ryan,您可以创建一个新项目,在其中逐步复制旧项目的部分内容,使您的团队能够同时在两个不同的分支上工作。好的部分是您必须迁移工作代码,这样您就不会像从头开始实施 430 个文件那样痛苦。从应用程序的最基础开始,始终迁移少量文件,逐渐达到合并效果。另外,您应该注意两个分支中已经合并的文件的更改。祝你好运。

于 2012-08-28T15:19:41.497 回答