如何检查 Mercurial 中潜在的合并/变基冲突?
有没有一种简单的方法可以检查合并/变基是否会产生文件冲突,而无需实际执行合并/变基?
我希望能够决定是否:
- 如果触及的文件集(我的与他们的)不同,则重新设置基准
- 如果我们一直在处理相同的文件,则合并。
因为如果我对两个头进行合并,而不是进行变基操作,那么错误的合并(由于人为错误以错误的方式解决冲突而引起)更容易检测和逆转。特别是如果我推动了更改,然后意识到有些事情搞砸了。
(不可能总是事先检查所有内容,因为我们没有完全全面的测试套件。)。
而且..我正在运行Windows。 :)
Is there a simple way to check if a merge/rebase will yield file conflicts, without actually performing the merge/rebase?
I want to be able to decide whether to:
- rebase if the touched file set (mine vs. theirs) are different
- merge if we've been messing with the same files.
Since a bad merge (caused by resolving conflicts the wrong way by human error) is easier to detect and reverse if I do a merge of two heads, rather than having done rebase. Especially if I push my changes and than later realized that something was messed up.
(It's not possible to always check everything beforehand, as we don't have a totally comprehensive test-suite.).
And.. I'm running Windows. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,在 Martin 的回答的帮助下,我提出了 rebaseif 扩展,它可以实现我想要的功能。
本质上,它尝试使用内部合并工具进行变基,如果失败(对于任何冲突都会这样做),它会中止并与用户首选的工具进行合并。
请参阅https://bitbucket.org/marcusl/ml-hgext/src/详细信息请参见tip/rebaseif.py。
更新
最近几个月,我又回去只进行合并,因为它本质上是安全的。非冲突变基可能仍然会把事情搞砸,因为依赖文件可能会影响更改。 (即变基会丢失合并前代码外观的信息)。
作为 rebaseif 作者,我建议使用普通的旧合并。 :)
So, with some aid from Martin's answer, I've come up with the rebaseif extension, which does what I want.
Essentially, it tries to rebase using the internal merge tool, if that fails (which it does for any conflict), it aborts and does a merge with the user's preferred tool.
See https://bitbucket.org/marcusl/ml-hgext/src/tip/rebaseif.py for details.
Update
In recent months, I've gone back to just do a merge, since it's inherently safe. A non-conflict rebase might still muck things up since dependent files can affect the change. (i.e. a rebase loses information of how the code looked before merge).
As the rebaseif author, I recommend to use plain old merge instead. :)
如果更改重叠,则没有理由使用
hg merge
,否则没有理由使用hg rebase
,因为hg rebase
在内部进行合并并让您解决它使用与hg merge
相同的工具。至于测试合并或变基是否会导致冲突,那么您可以
在 Mercurial 1.7 中使用来覆盖正常的 合并工具配置。 (
--tool internal:merge
部分是新的,在早期版本的 Mercurial 中使用--config ui.merge=internal:merge
。)合并后,
会告诉给你结果,你就会回到你开始的地方
There is no reason to use
hg merge
if the changes overlap andhg rebase
otherwise sincehg rebase
make a merge internally and will let you resolve it using the same tools ashg merge
.As for testing if a merge or rebase will cause conflicts, then you can use
in Mercurial 1.7 to override your normal merge tool configuration. (The
--tool internal:merge
part is new, use--config ui.merge=internal:merge
in earlier versions of Mercurial.)Following the merge,
will tell you the results and you will get back to where you started with
您可以查看两个变更集 REV1 和 REV2 是否影响任何相同的文件,执行以下操作:
如果有任何输出,则在两个修订版中都会触及同一文件。
这可以很容易地制作一个 shell 脚本,如下所示:
可以作为以下任何一个运行:
如果您真的想要花哨,您可以调整脚本以根据是否找到任何行来自动运行合并或变基。
如果你使用的是 Windows,我的上帝会帮助你。 :)
You can see if two changesets, REV1 and REV2, affect any of the same files doing something like:
If that has any output then the same file is touched in both revisions.
That could easily be made a shell script like:
which could be run as any of these:
If you really wanted to get fancy you could tweak the script to automatically run merge or rebase depending on whether or not any lines were found.
If you're on windows my god help you. :)