Convert a Mercurial Repository to Git

后端 未结 12 702
醉梦人生
醉梦人生 2020-12-07 11:19

I\'ve already tried hg2git through fast-export and I\'ve already tried hg-git.

Both with no success. hg2git actually worked, but I had to ask a friend who runs a Uni

相关标签:
12条回答
  • 2020-12-07 11:41

    Here is a simple example of how to export your local clone of a Mercurial repo to GitHub.

    First, add the hggit extension to your ~/.hgrc file if you have not already done so:

    [extensions]
    hggit =
    

    Then run the following commands from the root of your Mercurial repository:

    hg bookmark -r default master
    hg push -f git+ssh://git@github.com/bolinfest/plovr.git
    

    Personally, I had to specify -f when running hg push, though I suspect it is because I had some complicated branches in my Mercurial repo. You may not find it necessary for your migration.

    Make sure that you have the git+ssh: URI to your GitHub repo rather than the git: URI. (The git+ssh: URI is a bit harder to find in the new GitHub UI.)

    Depending on the size of your repo, running hg push may take awhile, so be patient. When you are done, you should be able to see your project on GitHub. In this example, my project was available at https://github.com/bolinfest/plovr.

    As you would expect, now anyone can clone your public GitHub repo as follows:

    git clone git@github.com:bolinfest/plovr.git
    
    0 讨论(0)
  • 2020-12-07 11:42

    Windows 7 64-bit Solution

    How to convert a Mercurial repo into a Git repo.

    This is one of the most asinine sequences of events I have ever had to figure out, but I am not a Python guy at all.

    My Start Environment

    • Visual Studio 2010/2012
    • TortoiseHg 2.8.2; Includes Mercurial 2.6.3 & Python 2.7.3
    • Git 1.8.3

    Errors I Got Along the Way

    • Could not find Python
    • Could not find Mercurial module in Python
    • Easy_Install does not exists
    • Could not compile Mercurial module

    What I Did

    • Had to install Python27 stand alone (http://www.python.org/)
    • Make sure to put path in Path in Environment Variables
    • Had to install Easy_Install (http://sourceforge.net/projects/pywin32/files/)
    • Make sure the Python Scripts path is also in Environment Variables
    • And get this... Had to go to MSDN and download full version of Visual Studio 2008 and only install C++ with the 64-bit option turned on (so Easy_Install could compile the Mercurial module for Python), but I could not get it to work with the Express edition because could not find the 64-bit option.

    Steps

    • In Command Console (after everything is installed)
      • C:\easy_install mercurial

    (If you installed everything you should see it download and compile the Mercurial module)

    • In Git Console
      • Follow steps by @mauvis-ledford and @benno (Thanks guys!!!)
    0 讨论(0)
  • I tried some of the other answers here and didn't have much luck. Here is the pretty straightforward method that what worked for me, after much trial and error:

    First, download the hggit extension and add it to your ~/.hgrc or mercurial.ini file if you have not already done so:

    [extensions]
    hggit=\path\to\hg-git
    

    For each branch you want to bring over to Git, add an Hg bookmark to the tip of the branch:

    hg bookmarks hg-default
    

    Then use hggit to create a git repo in the same folder as your current Hg repo by running hg gexport. A .git folder will have been added as a result. When you then delete the .hg folder from your repo, you will be left with a local git repo.

    0 讨论(0)
  • 2020-12-07 11:46

    If anyone is using Homebrew on OS X and wants to know the minor tweaks to get it to work properly please see the article here: http://www.ccannon.net/mercurial-to-git-conversion-with-homebrew.html

    0 讨论(0)
  • 2020-12-07 11:48

    There doesn't seem to be any reason you can't run hg2git on windows. It's python which has a windows port. Just make sure the proper libraries are there and run it on the window box.

    0 讨论(0)
  • 2020-12-07 11:49

    An easy way to convert between Git & Hg with no local process is to open a free KilnHg / Fogbugz account, create a private repo, push one format to it then pull in the other format, it works with both Git & Hg and (should) do seamless conversions.

    0 讨论(0)
提交回复
热议问题