Pages

Saturday, February 25, 2012

Convert Mercurial (hg) Repository to Git

The following instructions are for converting an hg repository to git on Windows 7.

INSTRUCTIONS
  1. Install Cygwin with python, hg and git
  2. Install fast-export

    You can try installing directly from the fast-export repository by issuing this command in the Cygwin console:
    git clone git://repo.or.cz/fast-export.git
    If your firewall doesn't like that command and responds with:
    Cloning into fast-export...
    repo.or.cz[0: 195.113.20.142]: errno=Connection timed out
    fatal: unable to connect a socket (Connection timed out)


    you can download an archive from here:
    http://repo.or.cz/w/fast-export.git/shortlog/refs/heads/master/

    Also, I was getting the following error: 
    IOError: [Errno 32] Broken pipe


    and was able to get around it by downloading an older version:

    fast-export-c8a45848968a21c3021489a6ba3ab1ffe5ef2a90.tar.gz
  3. Execute these commands in cygwin to create a working directory and initialize a new git repository:

    mkdir conversion
    cd conversion
  4. In Windows explorer, copy the fast-export folder from inside the archive into:

    C:\cygwin\home\<USERNAME>\conversion
  5. Also,  copy your existing mercurial repository, we'll call it convert.hg, into the same directory
  6. Execute the following commands:

    mkdir convert.git
    cd convert.git
    git init
    ~/conversion/fast-export/hg-fast-export.sh -r ~/conversion/convert.hg
ADDITIONAL NOTES

The directory structure created for this example was:

~/conversion
    /convert.git  # A new empty git repository
    /convert.hg   # Your existing mercurial repository
    /fast-export  # The fast-export directory we downloaded
REFERENCES

3 comments: