Help: export

hg export [OPTION]... [-o OUTFILESPEC] [-r] [REV]...

dump the header and diffs for one or more changesets

Print the changeset header and diffs for one or more revisions. If no revision is given, the parent of the working directory is used.

The information shown in the changeset header is: author, date, branch name (if non-default), changeset hash, parent(s) and commit comment.


'hg export' may generate unexpected diff output for merge changesets, as it will compare the merge changeset against its first parent only.

Output may be to a file, in which case the name of the file is given using a format string. The formatting rules are as follows:

literal "%" character
changeset hash (40 hexadecimal digits)
number of patches being generated
changeset revision number
basename of the exporting repository
short-form changeset hash (12 hexadecimal digits)
first line of the commit message (only alphanumeric characters)
zero-padded sequence number, starting at 1
zero-padded changeset revision number

Without the -a/--text option, export will avoid generating diffs of files it detects as binary. With -a, export will generate a diff anyway, probably with undesirable results.

Use the -g/--git option to generate diffs in the git extended diff format. See 'hg help diffs' for more information.

With the --switch-parent option, the diff will be against the second parent. It can be useful to review a merge.


  • use export and import to transplant a bugfix to the current branch:
    hg export -r 9353 | hg import -
  • export all the changesets between two revisions to a file with rename information:
    hg export --git -r 123:150 > changes.txt
  • split outgoing changes into a series of patches with descriptive names:
    hg export -r "outgoing()" -o "%n-%m.patch"

Returns 0 on success.

options ([+] can be repeated):

-o --output FORMAT print output to file with formatted name
--switch-parent diff against the second parent
-r --rev REV [+] revisions to export
-a --text treat all files as text
-g --git use git extended diff format
--binary generate binary diffs in git mode (default)
--nodates omit dates from diff headers

global options ([+] can be repeated):

-R --repository REPO repository root directory or name of overlay bundle file
--cwd DIR change working directory
-y --noninteractive do not prompt, automatically pick the first choice for all prompts
-q --quiet suppress output
-v --verbose enable additional output
--color TYPE when to colorize (boolean, always, auto, never, or debug)
--config CONFIG [+] set/override config option (use '')
--debug enable debugging output
--debugger start debugger
--encoding ENCODE set the charset encoding (default: UTF-8)
--encodingmode MODE set the charset encoding mode (default: strict)
--traceback always print a traceback on exception
--time time how long the command takes
--profile print command execution profile
--version output version information and exit
-h --help display help and exit
--hidden consider hidden changesets
--pager TYPE when to paginate (boolean, always, auto, or never) (default: auto)