自 hg 书编写以来,“hg backout”的行为是否发生了变化?

发布于 2024-11-30 02:44:44 字数 751 浏览 1 评论 0原文

我创建了一个新的存储库 test-backout,并在其中添加了一个新文件 file。然后,我每次都进行 4 次提交,并使用将提交编号附加到 file

echo [manually entered number] >> file
hg commit -m '[manually entered number]'

实际上,文件有:

init
1
2
3

根据 hg 书,如果我运行 hg backout --merge 2< /code>,我应该有:

init
1
3

但相反,它无法合并并打开我的 difftool (vimdiff),我得到 3 个选项:

init          | init          | init
1             | 1             |
2             |               |
3             |               |

我最初使用 --merge 选项尝试它,然后再次尝试没有它。我现在的问题是,是否还有办法让我知道:

init
1
3

我是否犯了错误或错过了什么,或者我是否坚持这些选择?

I created a new repository, test-backout, and added a new file in it, file. I then made 4 commits, each time, appending the number of the commit to file using

echo [manually entered number] >> file
hg commit -m '[manually entered number]'

In effect, file had:

init
1
2
3

According to the hg book, if I run hg backout --merge 2, I should have:

init
1
3

but instead, it fails to merge and opens up my difftool (vimdiff), and I get 3 options:

init          | init          | init
1             | 1             |
2             |               |
3             |               |

I initially tried it with the --merge option, then again without it. My question now is, is there still a way for me to get:

init
1
3

did I just make a mistake or miss something, or am I stuck with those options?

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

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

发布评论

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

评论(1

此生挚爱伱 2024-12-07 02:44:44

为什么你进行三向合并的一个重要因素是你的上下文太人为了,我会谈到这一点。

如果我获取一个 50 行文本文件并更改不同的部分并提交每个更改,我将不必解决冲突。我的意思是我有 4 个变更集:版本 0 添加文件,版本 1、2 和 3 分别更改文件的一个区域:开头、中间或结尾。

在这种情况下,当我执行 hg backout 2 时,它会反转 rev 2 并将这些更改合并到我的工作目录中,当我提交时,图表是线性的:

@  backout 2
|
o  3
|
o  2
|
o  1
|
o  initial

如果我改为执行>hg backout 2 --merge,它会自动将撤销作为其要撤销的修订的子项提交,然后将其与提示合并,在提交合并后生成分支图:

@    merge
|\
| o  backout 2
| |
o |  3
|/
o    2
|    
o    1
|    
o    initial

在这两种情况下,我没必要进行任何三向合并。您不会自动获取

init
1
3

而必须进行 3 路合并的原因是更改太接近了。每个变更集中的上下文和更改完全重叠(差异块的默认上下文行数为 3 行,其中包含仍在第四个变更集中的整个文件)。

类似的示例是,如果您有 3 个变更集,每个变更集都修改同一行。如果您像此处所做的那样取消了中间更改,您仍然会看到 3 路合并,您可能需要手动编辑才能正确。

顺便说一句,行为在 1.7 中确实发生了变化,正如 hg help backout 所证明的那样:

在版本 1.7 之前,没有 --merge 的行为相当于指定 --merge 后跟“hg update --clean”。取消合并并将 REV 的子项保留为要单独合并的头。

然而,我认为这并不完全是你所怀疑的。

A big factor in why you got the 3-way merge is that your context is too artificial, and I will get to that.

If I take a 50-line text file and change a different part and commit each change, I won't have to resolve conflicts. And what I mean is I have 4 changesets: rev 0 adds the file, revs 1, 2, and 3 each change one area of the file: the beginning, middle, or end.

In this situation, when I do hg backout 2, it makes a reverse of rev 2 and merges those changes to my working directory, and when I commit, the graph is linear:

@  backout 2
|
o  3
|
o  2
|
o  1
|
o  initial

If I instead do hg backout 2 --merge, it automatically commits the backout as a child of the revision it is backing out, and then merges that with the tip, producing a branched graph after I commit the merge:

@    merge
|\
| o  backout 2
| |
o |  3
|/
o    2
|    
o    1
|    
o    initial

In both situations, I didn't have to do any 3-way merging. The reason you don't automatically get

init
1
3

and instead have to do a 3-way merge is that the changes are too close together. The context and changes in each changeset are completely overlapped (default number of lines of context for a diff chunk is 3 lines, which encompasses the entire file still in your 4th changeset).

A similar example is if you had 3 changesets that each modified the same line. If you backed out the middle change like you're doing here, you would still be presented with a 3-way merge that you'll likely have to manually edit to get correct.

By the way, behavior did change in 1.7, as attested by hg help backout:

Before version 1.7, the behavior without --merge was equivalent to specifying --merge followed by "hg update --clean ." to cancel the merge and leave the child of REV as a head to be merged separately.

However, I don't think that's quite what you suspected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文