Convert a Mercurial Repository to Git

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

提交回复
热议问题