Mercurial或git优于svn的分支/合并有什么好处? [英] What are the benefits of Mercurial or git over svn for branching/merging?
问题描述
我曾听说过,使用git或mercurial合并分支比使用svn更容易。
在软件博客中读取最后一个Joel时,我没有得到这正是为什么。你可以提供一个具体的例子,与git / mercurial合并导致与svn相比较少的合并冲突吗?
一个简单的例子是git可以自动将合并转换为快进。例如,假设我有一个看起来像这样的分支:
Master:
A ---> B ---> C
我创建了一个基于Master的功能分支,并提交了新的提交D和E。
特点:$ b
$ b
A ---> B ---> C
\
D --->在svn中,当您将功能分支合并回主模块时,您必须创建一个全新的提交适用于师父的D和E的变化。所以,它看起来像:
主人:
A ---> B ---> C -----------------> F
功能:\ /
---> D ---> E - >
在git中,我们可以选择如何将分支功能合并到master中。如果我们做了
pre $ g $ rebit feature
code $ pre $
git会自动识别出这是一个微不足道的合并,并执行快进合并,这会将新提交添加到主分支。基础设施的结果是:
主人:
A - - > B ---> C ---> D ---> E
Master和Feature的头都指向提交E(换句话说,它们看起来完全是相同)。快进合并与您在svn中执行更新时发生的情况类似。
另外,您可以选择强制git创建合并提交。如果我们这样做:
git合并功能
git将创建一个合并提交。合并的结果是:
主人:
A ---> B ---> C -----------------> F
功能:\ /
---> D ---> E - >
提交F是D和E的组合。
I've heard for instance that merging branches with git or mercurial is easier than with svn.
Reading last Joel on software blog entry, I didn't get it exactly why. Could you provide a concrete example where merging with git/mercurial lead to less merge conflicts compared to svn please?
解决方案 One simple example is git can automatically convert a merge into a "fast forward". For example, let's say I have a branch that looks like this:
Master:
A ---> B ---> C
And I create a feature branch based on Master with new commits D and E.
Feature:
A --- > B ---> C
\
D ---> E
In svn, when you merge the feature branch back into master, you must create an entirely new commit that applies the changes of D and E on Master. So, it looks like:
Master:
A ---> B ---> C -----------------> F
Feature: \ /
---> D ---> E -->
In git we have a choice of how to incorporate the branch feature into master. If we do a
git rebase feature
git will automatically recognize that this is a trivial merge and perform a fast-forward merge, which will add the new commits to the master branch. The result of the rebase is:
Master:
A ---> B ---> C ---> D ---> E
Both the head of Master and Feature point at commit E (in other words, they look exactly the same). A fast-forward merge is similar to what happens when you do an update in svn.
Additionally, you have the option of forcing git to create a merge commit. If instead we do:
git merge feature
git will create a merge commit. The result of the merge is:
Master:
A ---> B ---> C -----------------> F
Feature: \ /
---> D ---> E -->
Commit F is the combination of D and E.
这篇关于Mercurial或git优于svn的分支/合并有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!