Mercurial how to create patch for one file in repo

export, mercurial

Solution

`hg export` exports individual changesets as separate entities.

If I understand you correctly, you need an answer to the question “What changes were made to `file.c` between revision 20 and revision 30?”, i.e. you need only need one diff file.

Here’s how you can do it:

hg diff file.c -r 20:30 > new.diff

As a more versatile approach, you can use `-I` (include file pattern) / `-X` (exclude).

Problem

I have a file called some/work/file.py in my repo. I have been working in the repo (on other files too besides file.py) and committing my changes and have gone from revision 20 to 30. How would I create a patch for only file.py from revisions 20 to 30 without including the other files? Something like: ``` hg export 20:30 file.py > new.patch ``` Have tried the command but does not work. Thank you

Original source