[英]What are the benefits of Mercurial or git over svn for branching/merging?
I've heard for instance that merging branches with git or mercurial is easier than with svn. 我听说过,例如将分支与git或mercurial合并比使用svn更容易。
Reading last Joel on software blog entry, I didn't get it exactly why. 在软件博客上阅读Joel的最后一篇,我并没有明白为什么。 Could you provide a concrete example where merging with git/mercurial lead to less merge conflicts compared to svn please?
你能提供一个具体的例子 ,与svn相比,与git / mercurial合并导致更少的合并冲突吗?
Check HGINIT out. 检查HGINIT 。 It's an article/tutorial by Joel Spolsky (not his latest blog entry) on the topic.
这是关于这个主题的Joel Spolsky(不是他最新的博客文章)的文章/教程。 You might find the Subversion Re-Education part specially interesting.
您可能会发现Subversion Re-Education部分特别有趣。
One simple example is git can automatically convert a merge into a "fast forward". 一个简单的例子是git可以自动将合并转换为“快进”。 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. 我创建了一个基于Master的功能分支,新的提交D和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. 在svn中,当您将功能分支合并回主服务器时,您必须创建一个全新的提交,在主服务器上应用D和E的更改。 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. 在git中,我们可以选择如何将分支功能合并到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. git会自动识别这是一个简单的合并并执行快进合并,这将把新的提交添加到主分支。 The result of the rebase is:
rebase的结果是:
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). Master和Feature的头部都指向提交E(换句话说,它们看起来完全相同)。 A fast-forward merge is similar to what happens when you do an update in svn.
快进合并类似于在svn中执行更新时发生的情况。
Additionally, you have the option of forcing git to create a merge commit. 此外,您可以选择强制git创建合并提交。 If instead we do:
相反,我们做:
git merge feature
git will create a merge commit. git将创建一个合并提交。 The result of the merge is:
合并的结果是:
Master:
A ---> B ---> C -----------------> F
Feature: \ /
---> D ---> E -->
Commit F is the combination of D and E. 提交F是D和E的组合。
Subversion conviniently implements only the single concept - fearure branches. Subversion很方便地只实现了单一的概念 - 恐惧分支。 This means one branch is always a
parent
and the other is feature
. 这意味着一个分支始终是
parent
分支,另一个分支是feature
。 Feature can pull the updates from parent over time (merge), but parent can pull feature's changes only once (merge --reintegrate) and then the child should be closed. 功能可以随着时间的推移从父项中提取更新(合并),但父项只能将功能的更改拉一次(merge --reintegrate),然后应该关闭子项。 It is sufficient in many cases but not always.
在许多情况下这已足够,但并非总是如此。 Not all branches are feature branches.
并非所有分支都是功能分支。 I've got a couple of examples.
我有几个例子。
release branch
. release branch
。 Suppose, you're preparing a release based on a thoroughly tested trunk revision.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.