Convert Mercurial project to Git
I need to convert a mercurial project to a git project, but I would like to keep the commit history intact. My current solution was to just remove hg related files and then git init && add manually the files I needed, but that would not keep the history. Are there any solutions to this?
You can try using fast-export:
cd ~
git clone https://github.com/frej/fast-export.git
git init git_repo
cd git_repo
~/fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo
git checkout HEAD
Also have a look at this SO question.
Ok I finally worked this out. This is using TortoiseHg on Windows. If you're not using that you can do it on the command line.
hggit
: Open a command line, enter an empty directory.
git init --bare .git
(If you don't use a bare repo you'll get an error like abort: git remote error: refs/heads/master failed to update
cd
to your Mercurial repository.
hg bookmarks hg
hg push c:/path/to/your/git/repo
In the Git directory: git config --bool core.bare false
(Don't ask me why. Something about "work trees". Git is seriously unfriendly. I swear writing the actual code is easier than using Git.)
Hopefully it will work and then you can push from that new git repo to a non-bare one.
If you want to import your existing mercurial repository into a 'GitHub' repository, you can now simply use GitHub Importer available here [Login required]. No more messing around with fast-export etc. (although its a very good tool)
You will get all your commits , branches and tags intact. One more cool thing is that you can change the author's email-id as well. Check out below screenshots:
链接地址: http://www.djcxy.com/p/6414.html上一篇: 在一个mercurial仓库中维护两个不同代码的最佳实践
下一篇: 将Mercurial项目转换为Git