合并到分支机构,无论你融入哪一个? [英] merging to branches, doesn't matter which one you merge into?

查看:126
本文介绍了合并到分支机构,无论你融入哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git版本1.7.5.4



我有大约5个分支。全部来自同一个初始分支。



我想将两个分支合并在一起。比如说branch1和branch2。这些分支有很多不同之处。



我目前正在使用branch1,并且刚刚意识到我在branch1中实现了一些我在branch1中实现的更改。



合并的最佳方法是什么?

 结帐分支2和合并分支1 

  checkout branch1并合并branch2 

或者你需要签出哪个分支合并与另一个分支?

解决方案

通常,如果两个分支都是主题或功能分支,则无关紧要。
$ b

但是,如果您有一个集成分支或一个标记已发布内容的分支,那么您肯定希望将长期存在的集成分支用作检出并将另一分支合并到其中的分支。

原因是合并提交会将第一个父提交标记为来访者主要分支。现在,您的树分支历史记录规范很容易。为了找到这个分支中第四个最后的提交,你只需要简单的

  git show head〜4 
code>

如果从另一个分支中的某个分支合并,则必须在合并完成时显式切换到第二个提交其他方式:

  git show head ^^ 2 ^^ 

由于其他原因,这会导致主要分支出现问题;将它们合并到主题或功能分支中被称为返回合并,并不是一个好主意。我记得当投稿人做到这一点时,Linus Torvalds吹了他的头把交椅。它不允许他清楚地分离他想要合并的主要修订的功能,因为功能分支会带来旧的测试合并,包括他不再需要的东西。



所以最后,如果一个分支更重要,而且不仅仅是一个功能,请检查并合并。您可以轻松地保留历史记录,因为您知道它的第一个父母始终位于该分支之前的位置。如果你不这样做,你将不得不依赖阅读合并提交消息,它只是不那么有趣。 :)



我写了一篇关于BpF的文章,其中介绍了严格保持分支机构的方法: http://dymitruk.com/blog/2012/02/05/branch-per-feature/


git version 1.7.5.4

I have about 5 branches. All from the same initial branch.

I want to merge 2 branches together. say, branch1 and branch2. These branches have a lot of differences.

I am currently working on branch1 and have just realized there are some changes I implemented in branch2 that I want in branch1.

what is the best way to merge?

checkout branch2 and merge branch1

or

checkout branch1 and merge branch2

Or doesn't it matter which branch you need to checkout to merge with another branch?

解决方案

Usually it does not matter if both branches are topic or feature branches.

However, if you have an integration branch or a branch that marks what's been published, you definitely want to use the long lived integration branch as the one that's checked out and merge the other one into it.

The reason for this is that the merge commit will mark the first parent commit as the one coming from the main branch. Your tree-ish specification for the history for that branch is easy now. To find the commit that was the 4th last in this branch, you simply

git show head~4

If you merged from the other branch somewhere in between, you would have to explicitly switch to the second commit wherever the merge was done the other way:

git show head^^2^^

This can cause problems with major branches for another reason; merging them into topic or feature branches is referred to as "back merging" and is not a good idea. I recall Linus Torvalds blowing his top when contributors did that. It would not allow him to cleanly separate what features he wanted to merge for a major revision as the feature branches would bring in an old test merge that included things he does not want anymore.

So in the end, if one branch is more significant and is more than just a feature, check it out and merge from there. You'll be able to keep it's history viewed easily as you know that it's first parent is always where that branch was before. If you don't, you'll have to rely on reading the merge commit messages and it's just not as fun. :)

I've written an article about BpF which shows a rigorous method of keeping branches organized: http://dymitruk.com/blog/2012/02/05/branch-per-feature/

这篇关于合并到分支机构,无论你融入哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆