Convert a Mercurial Repository to Git

后端 未结 12 703
醉梦人生
醉梦人生 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:56

    As of today, git distribution includes a tool to convert mercurial repositories to git, hg-to-git. If you have a recent git version installed, it is there. Worked very well for me.

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

    If you're really only looking to do it this once you can use hg export like this:

    hg export 0:tip -o all-changesets-in-one.patch
    

    or if git prefers only one patch per file you can create one per changeset like this:

    hg export 0:tip -o changeset-%r.patch
    

    presumably git apply can take one or the other of those formats.

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

    Did the following on my Mac to successfully export a Mercurial repo to Git (with full branches):

    mkdir myrepo; cd myrepo;
    git clone git://repo.or.cz/fast-export.git .
    rm -rf .git .gitignore
    git init
    ./hg-fast-export.sh -r ../path/to/local/hg/repo
    git clean -f # remove fast-export files
    
    0 讨论(0)
  • 2020-12-07 12:00

    If you happen to be using GitHub and your Mercurial repo is available via HTTP/HTTPS...

    In the course of using fast-import (a great tool, that converted my repo without issue) and pushing my new git repo from my dev box to GitHub, I noticed an option to "Import Code from Another Repository" during the "Quick Setup" portion of my git repo on GitHub.

    I tested it out and achieved the same results as using fast-import. Using the GitHub import option turned out to be a bit easier in my case than fast-import (again, nothing against that tool, and no, I don't work for GitHub). The steps which worked for me were:

    1. Create a new GitHub repo
    2. Choose the "Import Code" option in Quick Setup once the repo is created
    3. Enter the URL of a publicly available hg, svn, or tfs repo and press "Begin import" in the "Github Importer" dialog
    0 讨论(0)
  • 2020-12-07 12:01

    Have you tried tailor? It can pretty much convert anything to anything, as VCS go, and is even able to do it incrementally (that is, you convert once, then add new commits from the source to the target, without reconverting from scratch). You may not need it now, but it still is a nice feature.

    0 讨论(0)
  • 2020-12-07 12:05

    Here are all the pieces put together for a migration on Windows.

    Prerequisites

    • Git
    • Mercurial or TortoiseHg
    • Python 2.7 (3.x won't work)

    During install, allow binding to .sh files.
    Ensure that all tools are available in the PATH environment variable.

    Migration

    1. Open cmd.exe
    2. mkdir c:\git_work
    3. cd c:\git_work
    4. git clone http://repo.or.cz/r/fast-export.git
      This creates folder: c:\git_work\fast-export\
    5. Now you need mercurial libs for python. Either get them from here or do the following steps.
      Edit c:\git_work\fast-export\hg-fast-export.py:

      import sys # move this line up here
      # Add a new line that imports [mercurial libraries][2] from this zip:
      sys.path.append(r'C:\Program Files\TortoiseHg\library.zip')
      # ...above the old line:
      from mercurial import node
      
    6. mkdir MyNewGitRepo

    7. Copy content of fast-export to MyNewGitRepo, ignore .git*
    8. hg-fast-import.sh -r c:\Path\To\MyOldHgRepo
    9. If this fails with "Error: repository has at least one unnamed head..." call the last line with parameter: --force
    10. Remove the migration scripts:

      git clean -n # see what would happen
      git clean -f # delete migration files
      
    11. Restore missing files by resetting the index and working tree.

      git reset --hard
      
    0 讨论(0)
提交回复
热议问题