Mercurial:“合并和放弃更改"的任何方式? [英] Mercurial: Any way to "merge and discard changes"?

查看:69
本文介绍了Mercurial:“合并和放弃更改"的任何方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于以下内容的graphlog:

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

在(8)处,一切都应保持正常,除了(4)处悬空的额外头部.为了摆脱它,我必须合并(4)-.->(8),但是,由于(4)中没有我需要的东西,因此我可以放心地放弃所有的更改.我可以逐个文件手动合并(通常这没什么大不了的),但是出于我自己的目的-是否有一种简单的单行方式说将(4)与(8)合并,并且始终拿(8)"?

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)"?

推荐答案

是. internal:local内置合并工具.

$ hg merge 4 --tool internal:local

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

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.

分支它并在a中放入冲突:

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

返回并合并匿名头:

$ 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合并的每个文件上也要获取每个父文件的版本.

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

这篇关于Mercurial:“合并和放弃更改"的任何方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆