17

Possible Duplicate:
Converting a Mercurial (hg) repository to Git on Windows (7)

There's a Mercurial repository that I want to convert to Git, which is what we use at work. I have Mercurial (for Windows) installed, and I've already cloned the Hg repository locally. I'm stuck on trying to convert it.

Most of the pages I've found assume that I'm using Unix/Linux, and the most common recommendation, hg-fast-export, seems to work only in those OSes. I do have access to the Git Bash. I've gotten as far as this (line-wrapped for easier reading):

$ ~/codeingit/fast-export/hg-fast-export.sh -r
        ~/codeinmercurial/projectiwanttoconvert

In response, I get:

ImportError: No module named mercurial

I've read a number of web pages about this which, again, assume that I'm using Unix/Linux and that I have Mercurial installed for that.

Is there anyone who's successfully converted an Hg repository to Git on Windows, and can write a step-by-step guide to doing it?

Community
  • 1
  • 1
Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211
  • 1
    Technically, there's always the classic 3-step solution that works in cases like this: 1) get VMWare-Player, 2) get a Linux-distribution of your choice, 3) follow the Linux-based guides :-) – Christian Stieber Jul 03 '12 at 23:34
  • @cpeisert, I saw that one, but there's not anywhere near enough detail for me to be able to do what I want to do, unless cygwin actually includes mercurial, python, etc. out of the box. Does it? – Ryan Lundy Jul 04 '12 at 01:56
  • @Kyralessa, Yes, the Cygwin [packages](http://cygwin.com/packages/) include [mercurial](http://cygwin.com/packages/mercurial/), [python](http://cygwin.com/packages/python/), and [git](http://cygwin.com/packages/git/) out of the box as well as anything else you may need. – Christopher Peisert Jul 04 '12 at 02:24
  • 1
    @cpeisert, that's a pageful of stuff I don't know what to do with. Pretend I know nothing about Linux/Unix, and don't want to learn it all today, but just want to get this task done. What would I do, step by step? I don't mind installing stuff if it helps me get the task done. – Ryan Lundy Jul 04 '12 at 04:30
  • @Kyralessa, See answer below, which I tested on Windows 7 with a clean Cygwin install. – Christopher Peisert Jul 04 '12 at 07:14
  • 1
    @George Stocker, if that question had helped, I wouldn't have opened this one. – Ryan Lundy Jul 13 '12 at 17:27

1 Answers1

42

1) Install Cygwin or Bash on Windows 10

Cygwin

  • Run setup.exe
  • Select Install from Internet
  • In the Select Packages dialog box:
    • Click Install at the top of the tree (next to All) until it shows Default
    • Expand the Devel subtree: Install git (change from Skip to the version number)
    • In the Devel subtree: Install mercurial (change from Skip to the version number)
    • Install Python subtree (change from Default to Install)
    • Click Next
  • If prompted to resolve dependencies, click Next
  • Get a cup of coffee, watch your favorite movie, or take a long nap

After the Cygwin installation is complete, open a bash shell to run the commands indicated in the steps below. The shortcut to bash will be called Cygwin Terminal.

Windows 10

  • Install Bash on Windows 10
  • Get a cup of coffee
  • Open Bash and type the following:
    • sudo apt install git
    • sudo apt install mercurial

2) Install fast-export

Open terminal (bash shell) and install fast-export:

   https://github.com/frej/fast-export.git

3) Initialize new git repo and migrate mercurial repo

   mkdir new_git_repo
   cd new_git_repo
   git init
   ../fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo
   git checkout HEAD


Potential Error

fatal: Invalid raw date "<devnull@localhost> xxx -xxxx" in ident:  <><devnull@localhost> xxx -xxxx

Try adding an "authors.txt" file as described here, containing:

<>=devnull <devnull@localhost>

The command line now reads:

../fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo -A ../fast-export/authors
jpsimard-nyx
  • 8,587
  • 6
  • 32
  • 48
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
  • Thanks. I haven't had time at work to try this yet, but I will respond when I have time in the next week or two to try it out. – Ryan Lundy Jul 13 '12 at 17:28
  • 4
    after trying numerous other "fast"-export tutorials, this one did it. – Jake Berger Nov 07 '12 at 21:40
  • 2
    To anyone trying to convert from Mercurial to Git (on Windows)-- this is the best way. It might seem like overkill -- it is not. Save yourself a lot of headache, and follow these steps. – Richard West Sep 21 '15 at 20:45
  • 1
    Note that if you had cloned `fast-export` from git for windows, the shell script “hg-fast-export.sh” might have Windows line endings (CR-LF) in which case the script won't run properly. – Benoit Nov 03 '15 at 14:24
  • 1
    For those of you who aren't comfortable with the repo at the .cz domain, you can use `https://github.com/frej/fast-export` instead (thanks to comments at http://stackoverflow.com/a/6917665/284598). – GaTechThomas Jan 12 '17 at 16:47
  • to solve encoding problem with hg-fast-export you can use '-e' and '--fe' options (in my case by default comments imported well, but file names not: '--fe cp1251' solve this) – Sandre Oct 04 '19 at 15:31
  • I spent hours trying numerous recommended approaches, including Cygwin. With Cygwin I ran into Python issues. Many of the approaches were based on older versions of Mercurial, Python, Git, etc. What finally worked for me quick and easy was following the simple directions from Lorenzo Mori in http://www.lorenzomori.com/programming/convert-your-mercurial-repository-to-git-on-windows – Michael Russ Nov 22 '19 at 00:29