hg(Mercurial)版本库迁移到git版本库

来源:互联网 发布:excel如何删除一列数据 编辑:程序博客网 时间:2024/06/05 17:37

原文地址:http://www.cnblogs.com/rangeon/p/3673224.html

这几天没事干净搞迁移了,迁移完MVC又迁移版本库,还把工作电脑迁移了一下,开始用Win8.1了。这个迁移主要是因为实在不想在工作电脑上又装git又装hg了,点个右键出来一大堆菜单,况且现在git已经成为名符其实的“最高大上的分布式版本控制系统,没有之一”了,关键还是感觉git好用、用的顺手,就做了一个痛苦的决定:把hg干掉!XD

废话不多说,言归正传。

这个迁移其实很简单,就是使用fast-export迁移工具,在 Git Bash 中进行操作:

复制代码
1 git clone git://repo.or.cz/fast-export.git2 mkdir to_git3 cd to_git4 git init5 ../fast-export/hg-fast-export.sh -r /path/to/old/hg_repo_folder6 git checkout HEAD
复制代码

说明:

必须安装 hg 和 git,转换过程中需要用到。
环境变量的 Path 中要包含 Python 的目录。
必须执行 hg-fast-export.sh,不能直接执行 hg-fast-export.py,
直接执行 hg-fast-export.py 问题一大堆,也可能是我的 python 内力不足。


下面说说我遇到的一些问题(郁闷,怎么问题都让我遇上了)。

问题一
Error: Branch [master] modified outside hg-fast-export:
f8b24a1a35786cfcbb911592f4ad002ff76d4fae (repo) != None (cache)
解决:目标目录的git版本库不纯净,必须是空目录直接 git init 之后的。

问题二
repository has at least one unnamed head: hg r49
解决:加 --force 处理之

问题三 - 日志乱码
解决:修改hg-fast-export.py,对日志进行编码转换(170行左右)
(revnode,_,user,(time,timezone),files,desc,branch,_)=get_changeset(ui,repo,revision,authors)
desc = desc.decode('gbk').encode('utf-8')
branch=get_branchname(branch)

问题四 - 中文文件名乱码
解决:修改hg-fast-export.py,对文件名进行编码转换(134行左右)
开头加入:
reload(sys)
sys.setdefaultencoding('cp936')
找到:
wr('M %s inline %s' % (gitmode(manifest.flags(file)),file))
改为
wr('M %s inline %s' % (gitmode(manifest.flags(file)),file.encode('utf-8')))

 

分享一个我修改过的 hg-fast-export.py 文件:点击下载

0 0
原创粉丝点击