Mercurial 或 git 优于 svn 用于分支/合并的好处是什么? [英] What are the benefits of Mercurial or git over svn for branching/merging?
问题描述
例如,我听说用 git 或 mercurial 合并分支比用 svn 更容易.
I've heard for instance that merging branches with git or mercurial is easier than with svn.
阅读 Joel 上一篇关于软件博客的文章,我不明白为什么.您能否提供一个具体示例,其中与 svn 相比,与 git/mercurial 合并会导致更少的合并冲突?
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?
推荐答案
一个简单的例子是 git 可以自动将合并转换为快进".例如,假设我有一个看起来像这样的分支:
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:
大师:
A --->乙--->C
然后我创建了一个基于 Master 的特性分支,并带有新的提交 D 和 E.
And I create a feature branch based on Master with new commits D and E.
特点:
A --- > B ---> C
D ---> E
在 svn 中,当您将功能分支合并回 master 时,您必须创建一个全新的提交,将 D 和 E 的更改应用于 Master.所以,它看起来像:
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 -->
在 git 中,我们可以选择如何将分支功能合并到 master 中.如果我们做一个
In git we have a choice of how to incorporate the branch feature into master. If we do a
git rebase feature
git 会自动识别这是一个微不足道的合并并执行快进合并,这会将新提交添加到主分支.变基的结果是:
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:
大师:
A ---> B ---> C ---> D ---> E
Master 和 Feature 都指向提交 E(换句话说,它们看起来完全一样).快进合并类似于在 svn 中进行更新时发生的情况.
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.
此外,您可以选择强制 git 创建合并提交.如果我们这样做:
Additionally, you have the option of forcing git to create a merge commit. If instead we do:
git merge feature
git 将创建一个合并提交.合并的结果是:
git will create a merge commit. The result of the merge is:
Master:
A ---> B ---> C -----------------> F
Feature: /
---> D ---> E -->
Commit F 是 D 和 E 的组合.
Commit F is the combination of D and E.
这篇关于Mercurial 或 git 优于 svn 用于分支/合并的好处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!