Published on Nov 2, 2011

TortoiseHg - How to export changed files

TortoiseHg is excellent windows client for Mercurial Hg distributed source control management tool (SCM). It is a standalone installer that installs both Mercurial client and Mercurial Server in one shot. It has excellent performance on mainstream filesystems (Windows NTFS and linux EXT3), extensibility, and heap of features and settings.

The only thing I truly missed was the ability to export changed files between two arbitrary commits. Not patches, but whole files. This feature was only supported by SVN and I found it irreplacible while working on many projects.

Luckily, it is pretty easy to add this feature to a TortoiseHg client via extension - here's how.

For the purpose of this article let's assume that you already have TortoiseHg properly installed on your computer into default directory "c:\Program Files\TortoiseHg\".

1. Download python script called ""

Grab latest version from

2. Place script "" somewhere on your computer

I will assume that you will place the script into directory "c:\Program Files\TortoiseHg\extensions\" (create directory "extensions").

3. Install the script as TortoiseHg extension in global settings

If you only want to use this script in a particular repository, you need to edit settings only for that particular repository. I assume that most likely you want to use this feature for all repositories, therefore we add the extension into global settings.

Open Global settings and click "Edit file". Add following line to section [extensions]:

[extensions] exportfiles = c:\Program Files\TortoiseHg\extensions\

If the section [extensions] does not exist, just create it. You may also name "exportfiles" anything you like, just keep in mind that this will be the hg command to execute the extension (see further).

Editing configuration file in TortoiseHg global settings

Adding path to mercurial extension script

Click "Save" and close client window. Then open again - and now it should be compiled in source directory and installed on the "Extensions" tab.

Compiled python script

Added new extension "exportfiles"

4. Execute export of changed files into single directory

Now you can use command line commands to export any changeset.

hg exportfiles -r 10 ./export

 ... will export files changed in revision 10 into directory "./export"

hg exportfiles -r 10:20 ./export

 ... will export changed files from revision 10 up to revision 20

hg exportfiles -r 10:tip ./export

 ... will export all changed files from revision 10 up to latest commit (tip)

The directory "./export" will be created automatically if not present.

To ease repetitious tasks, you may want to create a simple command line file named e.g. "latestHgExport.bat" that will export each changeset into a separate directory:

echo off

rem This will export changed set of files between two arbitrary commints
rem see
rem Run this file in directory with HG repository

set YEAR=%date:~-4%
set MONTH=%date:~-7,2%
set DAY=%date:~3,2%
set HOUR=%time:~0,2%
set MIN=%time:~3,2%
set SEC=%time:~6,2%

rem set the "from revision" and "to revision"
set FROM=10
set TO=tip

rem set target output directory

echo "Exporting into %DESTINATION%..."

rem simple export only with "from revision"
rem hg exportfiles -r %FROM% %DESTINATION%

rem exporting "from - to revision"
hg exportfiles -r %FROM%:%TO% %DESTINATION%

Got a question?

Professional development of web applications and custom solutions. Consultancy services.