38

Is there a way to get the changes of two commits with mercurial? The second commit is not directly after the first one, there are some other ones between them.

I tried

hg diff [some params] --change xxxxx --change yyyyy > file.patch

but that only includes the last changeset.

If there is no way to achieve this with hg, is there maybe a tool to combine patches?

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
DerKuchen
  • 1,840
  • 1
  • 15
  • 15

3 Answers3

58

I came upon this page while trying to figure this very thing out. I found my solution via hg help diff .

hg diff -r <rev> -r <rev> worked for my needs (diffing between two tags)

Rod
  • 52,748
  • 3
  • 38
  • 55
the daniel
  • 596
  • 5
  • 2
  • 3
    You can diff between any two revisions, they don't need to be tagged. – Johannes Rudolph May 24 '10 at 06:21
  • 1
    Doesn't work for me in case commits are not directly after one another. In this case it includes also everything between them, which is exactly what needs to be avoided. – Georgii Ivankin Feb 28 '13 at 11:21
  • 2
    I found the `--only-files-in-revs` flag useful with this when the codebase is large, to force `hg` to only look at files modified in the revisions (`hg diff -r -r --only-files-in-revs`). – hnefatl Jul 16 '18 at 10:01
  • Option --only-files-in-revs not available in Mercurial v5.7.1 – Paul Jun 01 '21 at 09:12
6

An external diff

The extdiff extension will allow you to use your preferred external diff tool. In my case I use meld so day to day I run this type of command

hg meld -r <rev1> -r <rev2>

First enable the extdiff extension in the extensions section (I also have shelve & record enabled)

[extensions]
shelve =
record =
hgext.extdiff =

Then add this section ...

[extdiff]
cmd = meld
cmd.meld = /usr/bin/meld

to your .hgrc file. Obviously replace meld with the command used to launch your preferred tool

Chris McCauley
  • 25,824
  • 8
  • 48
  • 65
2

Export? One patch-file per changeset, something like

hg export --output %r.patch --rev A --rev B

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110