Mercurial:有什么方法可以“合并并放弃更改”吗?

发布于 2024-12-05 12:18:43 字数 623 浏览 0 评论 0原文

我有一个看起来像这样的图形日志:

(snip)
  | |
  | o    1) Other Dev: Commit
  | | \
  o | |  2) Me: Commit
/ | | |
| | o |  3) Other Dev: Commits with an error
| |/| |
| o |/   4) Me: Merge and commit
|  /|    
|/  |
o   |    5) Me: Realize there were bugs in the commit and take earlier version to merge with
|   o    6) Other Dev: Fixes error
o /      7) Me: committing some changes
|/
o        8) Me: Merge fixed tip

在 (8) 处,除了 (4) 处悬空的额外头部之外,一切都应该如此。为了摆脱它,我必须合并 (4) -.-> (8) 但是,由于 (4) 中没有我需要的内容,所以我可以安全地放弃它的所有更改。我可以逐个文件手动进行合并(通常这没什么大不了的),但为了我自己的启发 - 有没有一种简单的单行方法来表示“将 (4) 与 (8) 合并并且始终采取(8)”?

I have a graphlog that looks something like this:

(snip)
  | |
  | o    1) Other Dev: Commit
  | | \
  o | |  2) Me: Commit
/ | | |
| | o |  3) Other Dev: Commits with an error
| |/| |
| o |/   4) Me: Merge and commit
|  /|    
|/  |
o   |    5) Me: Realize there were bugs in the commit and take earlier version to merge with
|   o    6) Other Dev: Fixes error
o /      7) Me: committing some changes
|/
o        8) Me: Merge fixed tip

At (8), everything is as it should be with the exception of the dangling extra head at (4). To get rid of it I have to merge (4) -.-> (8) but, since there is nothing in (4) that I need, I can safely discard all of it's changes. I could do this merge manually file-by-file (and usually this isn't that big a deal) but for my own edification - is there a simple one-line way to say "merge (4) with (8) and always take (8)"?

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

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

发布评论

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

评论(1

烟花易冷人易散 2024-12-12 12:18:43

是的。 internal:local 内置合并工具。

$ hg merge 4 --tool internal:local

类似地,还有 internal:other 选择文件的其他版本作为合并版本。

下面是一个说明发生了什么的示例,从具有单个文件的存储库开始:

$ echo a >> a
$ hg ci -Am.
adding a
$ echo a >> a
$ hg ci -Am.

对其进行分支并将冲突放入 a 中:

$ hg up 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ echo b >> a

同时在合并的分支中添加另一个文件:

$ echo b >> b
$ hg ci -Am.
adding b
created new head

返回并合并匿名头:

$ hg up 1
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ hg merge 2 --tool internal:local
1 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

当然,此时如果没有合并工具,我们就会在 a 上遇到冲突。但是使用合并工具,我们告诉 Mercurial 在与 cset 合并也触及的每个文件上采用第一个父级的版本。

$ hg st
M a
M b
$ cat a
a
a
$ cat b
b

Yes. The internal:local builtin merge tool.

$ hg merge 4 --tool internal:local

Similarly there's internal:other that picks the other version of files as the merged version.

Here's an example to clarify what's going on, start off with a repo with a single file:

$ echo a >> a
$ hg ci -Am.
adding a
$ echo a >> a
$ hg ci -Am.

Branch it and put a conflict in a:

$ hg up 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ echo b >> a

Also add another file just in the merged in branch:

$ echo b >> b
$ hg ci -Am.
adding b
created new head

Go back and merge the anonymous head:

$ hg up 1
1 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ hg merge 2 --tool internal:local
1 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

Naturally at this point without the merge tool we'd get a conflict on a. But using the merge tool, we're telling Mercurial to take the version of the first parent on every file that the merged with cset has also touched.

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