如何在Mercurial中应用补丁并在失败时显示差异工具

8 投票
2 回答
4309 浏览
提问于 2025-04-17 05:37

我想在Mercurial中应用补丁:

hg import patch_name.patch

但是如果我遇到错误 abort: patch failed to apply,Mercurial会生成 *.rej 文件。

有没有办法使用kdiff或者vim-diff来解决冲突呢?

2 个回答

2

我敢打赌,hg会返回一个错误代码。也许你可以把hg import放在一个脚本里,这个脚本可以捕捉到返回的错误代码,如果有错误的话就执行你想要的操作?大概可以这样做:

#!/bin/sh
# run the script by typing `hgimp patch_name.patch`
# $1 below will contain patch_name.patch
hg import $1

# if the return code is not equal to 0, run vimdiff or whatever
if [ ! "$?" -eq '0' ]; then
    # run your diff/cleanup commands here
fi
3

没有办法直接做到这一点。推荐的做法是打开文件和.rej文件,然后手动把被拒绝的部分合并进去。

撰写回答