与 svn 相比,Mercurial 或 git 在分支/合并方面有哪些优势?

发布于 2024-08-26 13:03:22 字数 154 浏览 5 评论 0原文

例如,我听说用 git 或 Mercurial 合并分支比用 svn 更容易。

阅读了 Joel 上一篇关于软件的博客文章,我不明白为什么。您能否提供一个具体示例,其中与 svn 相比,与 git/mercurial 合并会导致更少的合并冲突?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

有深☉意 2024-09-02 13:03:22

一个简单的例子是 git 可以自动将合并转换为“快进”。例如,假设我有一个如下所示的分支:

Master:

A ---> B---> C

我基于 Master 创建了一个功能分支,并添加了新的提交 D 和 E。

功能:

A --- > B ---> C
                \
                 D ---> E

在 svn 中,当您将功能分支合并回 master 时,您必须创建一个全新的提交来应用 D 和 E 的更改。 E上师父。所以,它看起来像:

Master:
    A ---> B ---> C -----------------> F
Feature:           \                  /
                    ---> D ---> E -->

在 git 中,我们可以选择如何将分支功能合并到 master 中。如果我们执行

git rebase feature

git 操作,它会自动识别出这是一个简单的合并并执行快进合并,这会将新的提交添加到 master 分支。 rebase的结果是:

Master:

A ---> B ---> C ---> D ---> E

Master和Feature的头都指向提交E(换句话说,它们看起来一模一样)。快进合并类似于在 svn 中进行更新时发生的情况。

此外,您可以选择强制 git 创建合并提交。如果我们这样做:

git merge feature

git 将创建一个合并提交。合并的结果是:

Master:
    A ---> B ---> C -----------------> F
Feature:           \                  /
                    ---> D ---> E -->

提交F是D和E的组合。

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.

孤独岁月 2024-09-02 13:03:22

检查 HGINIT 。这是 Joel Spolsky(不是他最新的博客文章)关于该主题的文章/教程。您可能会发现 Subversion Re-Education 部分特别有趣。

Check HGINIT out. It's an article/tutorial by Joel Spolsky (not his latest blog entry) on the topic. You might find the Subversion Re-Education part specially interesting.

独闯女儿国 2024-09-02 13:03:22

Subversion 仅方便地实现了单一概念 - 分支分支。这意味着一个分支始终是父级,另一个是功能。功能可以随着时间的推移从父级提取更新(合并),但父级只能提取功能的更改一次(合并-重新集成),然后应该关闭子级。在许多情况下它就足够了,但并非总是如此。并非所有分支都是功能分支。我有几个例子。

  1. 第一的。一个很好的例子是发布分支。假设您正在准备一个基于经过彻底测试的主干修订版的版本。您从所需的主干修订版创建一个发布分支。现在您不会受到任何后续主干修改的影响。但是您可能希望将修补程序提交到发布分支,并且您可能希望将它们反向移植到主干而不关闭发布分支。这不能用 svn 的功能分支来实现。使用 svn,你必须等到不再需要你的发布分支,然后重新集成它。或者手动向后移植修补程序。
  2. 第二。每个团队或每个开发人员分支。没有现成的例子来说明它们何时真正有用,但你肯定不会喜欢它们在 svn 中。同步这样的分支会很痛苦。

Subversion conviniently implements only the single concept - fearure branches. This means one branch is always a parent and the other is 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. It is sufficient in many cases but not always. Not all branches are feature branches. I've got a couple of examples.

  1. First. A good example is a release branch. Suppose, you're preparing a release based on a thoroughly tested trunk revision. You make a release branch from the desired trunk revision. Now you're not affected by any subsequent trunk modifications. But you may want to commit hotfixes to the release branch and you may want to backport those to trunk without closing the release branch. This cannot be implemented with svn's feature branches. With svn you will have to wait until your release branch is no longer needed and then reintegrate it. Or to backport the hotfixes by hand.
  2. Second. Per-team or per-developer branches. Don't have a ready example of when they're really useful, but you won't like them in svn for sure. It'll be painful to synchronize such branches.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文