Using Mercurial, is there an easy way to diff my working copy with the tip file in the default remote repository

有些话、适合烂在心里 提交于 2019-11-30 06:51:35
Ted Naleid

After some digging, I came across the Rdiff extension that does most of what I want it to.

It doesn't come with mercurial, but it can be installed by cloning the repository:

hg clone http://hg.kublai.com/mercurial/extensions/rdiff 

And then modifing your ~/.hgrc file to load the extension:

[extensions] 
rdiff=~/path/to/rdiff/repo/rdiff.py

It's a little quirky in that it actually modifies the existing "hg diff" command by detecting if the first parameter is a remote URL. If it is then it will diff that file against your tip file in your local repo (not the working copy). This as the remote repo is first in the arguments, it's the reverse of what I'd expect, but you can pass "--reverse" to the hg diff command to switch that around.

I could see these being potential enhancements to the extension, but for now, I can work around them with a bash/zsh shell function in my starup file. It does a temp checkin of my working copy (held by the mercurial transaction so it can be rolled back), executes the reverse diff, and then rolls the transaction back to return things back to the way they were:

hgrdiff() {
    hg commit -m "temp commit for remote diff" && 
    hg diff --reverse http://my_hardcoded_repo $* &&
    hg rollback      # revert the temporary commit
}

And then call it with:

hgrdiff <filename to diff against remote repo tip>

You could try having two repositories locally - one for incoming stuff, and one for outgoing. Then you should be able to do diff with any tools. See here:

http://weblogs.java.net/blog/kohsuke/archive/2007/11/using_mercurial.html

to expand on Lars method (for some reason comment doesn't work), you can use the -R option on the diff command to reference a local repository. That way you can use the same diff application that you've specified within hg

Using templates you can get a list of all changed files:

hg incoming --template {files}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!