Skip to content

Commit d3e6023

Browse files
committed
Merge pull request #181 from networm/09-git-and-other-scms_import-hg
Translate 09-git-and-other-scms import-hg
2 parents 80e2d4d + a341623 commit d3e6023

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

book/09-git-and-other-scms/sections/import-hg.asc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
==== Mercurial
22

33
(((Mercurial)))(((Importing, from Mercurial)))
4-
Since Mercurial and Git have fairly similar models for representing versions, and since Git is a bit more flexible, converting a repository from Mercurial to Git is fairly straightforward, using a tool called "hg-fast-export", which you'll need a copy of:
4+
因为 Mercurial Git 在表示版本时有着非常相似的模型,也因为 Git 拥有更加强大的灵活性,将一个仓库从 Mercurial 转换到 Git 是相当直接的,使用一个叫作“hg-fast-export”的工具,需要从这里拷贝一份:
55

66
[source,console]
77
----
88
$ git clone http://repo.or.cz/r/fast-export.git /tmp/fast-export
99
----
1010

11-
The first step in the conversion is to get a full clone of the Mercurial repository you want to convert:
11+
转换的第一步就是要先得到想要转换的 Mercurial 仓库的完整克隆:
1212

1313
[source,console]
1414
----
1515
$ hg clone <remote repo URL> /tmp/hg-repo
1616
----
1717

18-
The next step is to create an author mapping file.
19-
Mercurial is a bit more forgiving than Git for what it will put in the author field for changesets, so this is a good time to clean house.
20-
Generating this is a one-line command in a `bash` shell:
18+
下一步就是创建一个作者映射文件。
19+
Mercurial 对放入到变更集作者字段的内容比 Git 更宽容一些,所以这是一个清理的好机会。
20+
只需要用到 `bash` 终端下的一行命令:
2121

2222
[source,console]
2323
----
2424
$ cd /tmp/hg-repo
2525
$ hg log | grep user: | sort | uniq | sed 's/user: *//' > ../authors
2626
----
2727

28-
This will take a few seconds, depending on how long your project's history is, and afterwards the `/tmp/authors` file will look something like this:
28+
这会花费几秒钟,具体要看项目提交历史有多少,最终 `/tmp/authors` 文件看起来会像这样:
2929

3030
[source]
3131
----
@@ -37,10 +37,10 @@ Bob Jones <[email protected]>
3737
Joe Smith <[email protected]>
3838
----
3939

40-
In this example, the same person (Bob) has created changesets under four different names, one of which actually looks correct, and one of which would be completely invalid for a Git commit.
41-
Hg-fast-export lets us fix this by adding `={new name and email address}` at the end of every line we want to change, and removing the lines for any usernames that we want to leave alone.
42-
If all the usernames look fine, we won't need this file at all.
43-
In this example, we want our file to look like this:
40+
在这个例子中,同一个人(Bob)使用不同的名字创建变更集,其中一个实际上是正确的,另一个完全不符合 Git 提交的规范。
41+
Hg-fast-export 通过向我们想要修改的行尾添加 `={new name and email address}` 来修正这个问题,移除任何我们想要保留的用户名所在的行。
42+
如果所有的用户名看起来都是正确的,那我们根本就不需要这个文件。
43+
在本例中,我们会使文件看起来像这样:
4444

4545
[source]
4646
----
@@ -50,7 +50,7 @@ bob jones <bob <AT> company <DOT> com>=Bob Jones <[email protected]>
5050
5151
----
5252

53-
The next step is to create our new Git repository, and run the export script:
53+
下一步是创建一个新的 Git 仓库,然后运行导出脚本:
5454

5555
[source,console]
5656
----
@@ -59,9 +59,9 @@ $ cd /tmp/converted
5959
$ /tmp/fast-export/hg-fast-export.sh -r /tmp/hg-repo -A /tmp/authors
6060
----
6161

62-
The `-r` flag tells hg-fast-export where to find the Mercurial repository we want to convert, and the `-A` flag tells it where to find the author-mapping file.
63-
The script parses Mercurial changesets and converts them into a script for Git's "fast-import" feature (which we'll discuss in detail a bit later on).
64-
This takes a bit (though it's _much_ faster than it would be over the network), and the output is fairly verbose:
62+
`-r` 选项告诉 hg-fast-export 去哪里寻找我们想要转换的 Mercurial 仓库,`-A` 标记告诉它在哪找到作者映射文件。
63+
这个脚本会分析 Mercurial 变更集然后将它们转换成 Gitfast-import”功能(我们将在之后详细讨论)需要的脚本。
64+
这会花一点时间(尽管它比通过网格 _更_ 快),输出相当的冗长:
6565

6666
[source,console]
6767
----
@@ -109,9 +109,9 @@ $ git shortlog -sn
109109
365 Joe Smith
110110
----
111111

112-
That's pretty much all there is to it.
113-
All of the Mercurial tags have been converted to Git tags, and Mercurial branches and bookmarks have been converted to Git branches.
114-
Now you're ready to push the repository up to its new server-side home:
112+
那看起来非常好。
113+
所有 Mercurial 标签都已被转换成 Git 标签,Mercurial 分支与书签都被转换成 Git 分支。
114+
现在已经准备好将仓库推送到新的服务器那边:
115115

116116
[source,console]
117117
----

0 commit comments

Comments
 (0)