【发布时间】:2015-04-09 14:06:45
【问题描述】:
我有一个三向合并分支合并:
git checkout master
git merge BranchA
>> Fast-forward merge
git merge BranchB
>> Three-way-merge (prompts for a merge commit message)
我的问题有两个:
-
我怎样才能中止合并?通过三向合并,我向编辑器展示了在哪里编写合并提交消息。 但是如果我不保存就退出,git 无论如何都会继续进行合并(只是合并提交消息将是默认消息,而不是我可以编写但中止的消息)
commit 11111233 Merge 'BranchB' into master虽然显然没有确认提交消息,但我希望不会发生合并(与我不确认正常提交消息时的行为相同)
-
两个合并分支的提交是否会按时间顺序排序?
还是首先(在
git log)我会看到来自 BranchA 的提交,然后是来自 BranchB 的提交?
编辑
为了更好地解释第二个问题,我做了一个测试: 从 master 分支开始的 2 个分支(A 和 B)。我在 B 上进行了提交,然后在 A 上,然后再次在 B 上,最后再次在 A 上。 然后我将 BranchA 合并到 master 中。然后将BranchB变成master。
但是当我在master上git log时,这就是结果,也是我问第二个问题的原因:
commit 730fdd4d328999c86fa4d3b6120ac856ecaccab1
Merge: 7eb581b cc1085a
Author: Arthur Conandoyle <Arthur.Conandoyle@live.com>
Date: Mon Feb 9 21:24:27 2015 +0100
Merge branch 'BranchB' into master_COPY
commit 7eb581b39a8402e1694cc4bf4eab4a3feb1143f8
Author: Arthur Conandoyle <Arthur.Conandoyle@live.com>
Date: Mon Feb 9 21:23:18 2015 +0100
BranchA) - This should be the (second) last change of the branch, and be the
most recent into the git log, even if I merge another branch into master,
AFTER the one where we are committing this.
commit cc1085a6aaa2ee4b26d3c3fbb93bee863d9e7c28
Author: Arthur Conandoyle <Arthur.Conandoyle@live.com>
Date: Mon Feb 9 21:20:29 2015 +0100
(BranchB) - Add settings to the last new features
commit 5f5b846a2f89886d01244ba77af941f554233b51
Author: Arthur Conandoyle <Arthur.Conandoyle@live.com>
Date: Mon Feb 9 21:18:54 2015 +0100
(BranchA) - Add some changes
commit 92a57a56b6b7c9694fbedda71b8070fc58683dde
Author: Arthur Conandoyle <Arthur.Conandoyle@live.com>
Date: Mon Feb 9 21:18:17 2015 +0100
(BranchB) - Some changes
commit 221765476e348833cf8da73b1bf5239f3d4240e8
Author: Arthur Conandoyle <Arthur.Conandoyle@live.com>
Date: Tue Feb 3 12:12:19 2015 +0100
Change (this is the last commit of the parent 'master' branch)
(正如 Srdjan Grubor 所写)我本来预计首先(按时间顺序)来自合并的 BranchA 和 THEN 所有的提交从合并的 BranchB 提交,按照合并的顺序...
.. 但有趣的是,git log 却按时间顺序显示它们,并且提交未按分支分组显示!
【问题讨论】:
-
尝试写入 empty 消息以中止,即删除所有内容并保存空文件。
-
很好的建议。这解决了问题(我会说 "bug")并允许中止 merging!
-
这不是错误。空提交消息中止提交(除非明确允许);对于所有提交都是如此:普通提交和合并提交。如果您使您的正常提交消息模板具有一些初始值,那么退出也不会中止。这是提交的内容,而不是您是否更改了某些内容的事实。否则,只接受默认消息是行不通的。
-
短语“三路合并”并不是指(无论如何在 git 中)将 两个 其他分支带入您当前的分支。相反,它指的是当将 一个 其他分支引入当前分支时,该过程是通过找到“合并基础”(最近的共同祖先)然后组合两组更改来完成的: -base vs
HEAD,合并基础 vs other-branch-tip。在 git 中,当HEAD是合并基础时会发生“快进”合并。 -
@jthill:在共同祖先是当前
HEAD的情况下,git 仍然会进行双向合并(也称为快进)。因此,至少在read-tree的-m选项的文档中已经提到了这一点。不确定其他人是否还在使用该术语...
标签: git github merge git-commit abort