Migrating Mercurial to GitHub

孤者浪人 提交于 2019-12-22 17:55:32

问题


I want to move from Google Code and Mercurial to Git and GitHub while keeping all branches and version history.

So far it seems like the Hg-Git mercurial plugin (http://hg-git.github.com/) is my only option. I tried to follow the install instructions but am in a little over my head. Here's where I am:

  • I installed Microsoft Visual C++ 2008
  • I installed Python 2.7.3
  • I installed setuptools
  • I added the following to my mercurial.ini in TortoiseHg:
[extensions]
hgext.bookmarks =
hggit = 

Now when I run:

C:\Python27\Scripts>easy_install.exe hg-git

I get the following:

Searching for hg-git
Best match: hg-git 0.3.3
Processing hg_git-0.3.3-py2.7.egg
hg-git 0.3.3 is already the active version in easy-install.pth

Using c:\python27\lib\site-packages\hg_git-0.3.3-py2.7.egg
Processing dependencies for hg-git
Searching for dulwich>=0.8.0
Reading http://pypi.python.org/simple/dulwich/
Reading http://samba.org/~jelmer/dulwich
Reading http://launchpad.net/dulwich
Best match: dulwich 0.8.5
Downloading http://samba.org/~jelmer/dulwich/dulwich-0.8.5.tar.gz
Processing dulwich-0.8.5.tar.gz
Running dulwich-0.8.5\setup.py -q bdist_egg --dist-dir c:\users\lee\appdata\local\temp\easy_install-3qgeev\dulwich-0.8.5\egg-dist-tmp-ciyt_4

And then a bunch of errors that look like this:

Traceback (most recent call last):
  File "C:\Python27\Scripts\easy_install-script.py", line 8, in <module>
    load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 1712, in main
    with_ei_usage(lambda:
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 1700, in with_ei_usage
    return f()
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 1716, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "C:\Python27\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 211, in run
    self.easy_install(spec, not self.no_deps)
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 446, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 481, in install_item
    self.process_distribution(spec, dists[0], deps, "Using")
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 519, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 563, in resolve
    dist = best[req.key] = env.best_match(req, self, installer)
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 799, in best_match
    return self.obtain(req, installer) # try and download/install

Not sure what to try next. I also tried following tips from Cloning github repo with hggit but I'm missing something obvious. Any help would be greatly appreciated.


回答1:


Just draft and some notes&thoughts:

  • In order to use TortoiseHG (on Windows, XP SP3 if it matter) Python is not mandatory - I work with THG without Python/setuptools/pip
  • TortoiseHG (32bit or 64bit) from Bitbucket are self-sufficient Mercurial in Windows-world
  • I added hg-git extension to my TortoiseHG by hand
    • cloned hg-git from bitbucket repo into local dir

\TortoiseHg\plugins>dir /B

hg-git

...

  • added hg-git extension to global mercurial.ini (Documents and Settings\Badger\mercurial.ini)

[extensions]

...

hggit = c:\Program Files_Tools\TortoiseHg\plugins\hg-git\hggit

...

  • bookmarks extension, as default extension, bundled with THG, was enabled in GUI some versions ago and can be found in mercurial.ini now as bookmarks = without corresponding checkbox in Settings-Extensions

  • With functional hg-git in TortoiseHG (clone, pull, push without errors for some Git-repo) you can try to convert external Mercurial repo to external Git repo

    • clone CG Mercurial repo to local (Mercurial) repo
    • create new empty Git repo on Github (verify authentification and other possible issues)
    • add second remote repo (GUI - "Synchonize" tab, by hand - new string in [paths] section in repo's .hg\hgrc), for me only git+ssh://git@github.com/username/reponame.git URL (with key-based authentification over PageAnt) is transparent solution
    • push local repo to github
    • Have Fun

Screenshot is just example of my active Git repo on GitHub and attempt to illustrate my words by a live source




回答2:


I also struggled with hg-git. I come up with a weird solution.

I imported hg repo with https://import.github.com/new It is not weird and must be what you look for.


The weird and bonus section is below:

  • I created a hg mirror repo on http://bitbucket.org
  • I created a local hg repository within git repository.
  • I added .hg/ to my .gitignore
  • Add .hg/ and .git/ to your .gitignore file .git/ .hg/
  • Enter the .hg directory in local repo and symlink your .gitignore file as .hgignore with

    $ ln -s ../.gitignore .hgignore

  • Now any changes made to your .gitignore are considered also by hg

    $ git add .gitignore -am 'gitignore'

    $ hg add .gitignore -am 'Do not forget to symlink .gitignore as .hgignore in .hg/ folder'

    $ hg push default

    $ git push origin master

Conclusion: While it looks inefficient, it takes advantages of github while not losing hg repo and database and gives opportunity to use both git and hg



来源:https://stackoverflow.com/questions/12555843/migrating-mercurial-to-github

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!