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

前端 未结 4 2084
遇见更好的自我
遇见更好的自我 2020-12-30 05:49

When using mercurial, I\'d like to be able to diff the working copy of a file with the tip file in my default remote repository. Is there an easy way to do this?

I

4条回答
  •  心在旅途
    2020-12-30 06:37

    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 
    

提交回复
热议问题