descriptionPrograms to feed git-fast-import
last changeSun, 14 May 2017 12:32:59 +0000 (14 14:32 +0200)
content tags

hg-fast-export.(sh|py) - mercurial to git converter using git-fast-import


Most hg-* scripts are licensed under the [MIT license] ( and were written by Rocco Rutte with hints and help from the git list and #mercurial on freenode. is licensed under GPLv2 since it copies some code from the mercurial sources.

The current maintainer is Frej Drejhammar


Using hg-fast-export is quite simple for a mercurial repository :

mkdir repo-git # or whatever
cd repo-git
git init -r <repo>

Please note that hg-fast-export does not automatically check out the newly imported repository. You probably want to follow up the import with a git checkout-command.

Incremental imports to track hg repos is supported, too.

Using hg-reset it is quite simple within a git repository that is hg-fast-export'ed from mercurial: -R <revision>

will give hints on which branches need adjustment for starting over again.

When a mercurial repository does not use utf-8 for encoding author strings and commit messages the -e <encoding> command line option can be used to force fast-export to convert incoming meta data from to utf-8. This encoding option is also applied to file names.

In some locales Mercurial uses different encodings for commit messages and file names. In that case, you can use --fe <encoding> command line option which overrides the -e option for file names.

As mercurial appears to be much less picky about the syntax of the author information than git, an author mapping file can be given to hg-fast-export to fix up malformed author strings. The file is specified using the -A option. The file should contain lines of the form FromAuthor=ToAuthor. The example below will translate User <garbage<> to User <>.

-- Start of --
User <garbage<>=User <>
-- End of --

Tag and Branch Naming

As Git and Mercurial have differ in what is a valid branch and tag name the -B and -T options allow a mapping file to be specified to rename branches and tags (respectively). The syntax of the mapping file is the same as for the author mapping.


hg-fast-export supports multiple branches but only named branches with exactly one head each. Otherwise commits to the tip of these heads within the branch will get flattened into merge commits.

As each git-fast-import run creates a new pack file, it may be required to repack the repository quite often for incremental imports (especially when importing a small number of changesets per incremental import).

The way the hg API and remote access protocol is designed it is not possible to use hg-fast-export on remote repositories (http/ssh). First clone the repository, then convert it.

Design was designed in a way that doesn't require a 2-pass mechanism or any prior repository analysis: if just feeds what it finds into git-fast-import. This also implies that it heavily relies on strictly linear ordering of changesets from hg, i.e. its append-only storage model so that changesets hg-fast-export already saw never get modified.

Submitting Patches

Please use the issue-tracker at github to report bugs and submit patches.

9 days ago Frej DrejhammarFix crash when a branch name starts with '/'master
2017-01-01 Emilian BoldShow warning when core.ignoreCase is true
2016-12-28 Frej DrejhammarMake backup copies of state files
2016-10-01 Frej DrejhammarFix broken support for bare repositories
2016-09-14 Frej DrejhammarDo not rely on git internals, support Git >= 2.10v160914
2016-04-15 Frej DrejhammarFix "Branch ... modified outside hg-fast-export...... v160415
2016-04-15 Frej DrejhammarSwitch from os.popen() to subprocess.check_output(...
2016-04-03 Frej DrejhammarWarn if one of the marks, mapping, or heads files are...
2016-04-02 Frej Drejhammarverify_heads() needs to be aware of the branch renaming map
2016-04-02 Frej DrejhammarWarn if opening a mapping file fails
2016-04-02 Frej DrejhammarRefactor sanitize_name() to know about renaming map
2016-04-02 Frej DrejhammarExplain why it is a bad idea to change sanitize_name()
2016-01-29 Frej DrejhammarRemove obsolete and unsupported SVN tools
2016-01-10 Frej DrejhammarMake --hg-hash work in incremental mode
2015-12-12 Mark RaymondUse backquotes
2015-12-12 Mark RaymondUse GitHub markdown
8 months ago v160914 v160914
9 months ago v160415 Tag version 160415
9 days ago master
9 years ago git-p4
9 years ago hanwen
Cached version (656s old) 
fast-export/rorcz.git Local fork with needed fixes 6 months ago
fast-export/benizi.git 4 years ago
fast-export/fast-export-unix-compliant.git dereckson@espace... 4 years ago
fast-export/dharding.git 5 years ago
fast-export/barak.git tweaks and maybe debian packaging info 5 years ago