Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate 09-git-and-other-scms import-hg v2 #181

Merged
merged 5 commits into from
Aug 14, 2015
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions book/09-git-and-other-scms/sections/import-hg.asc
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
==== Mercurial

(((Mercurial)))(((Importing, from Mercurial)))
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:
因为 Mercurial Git 在表示版本时有着非常相似的模型,也因为 Git 拥有更加强大的灵活性,将一个仓库从 Mercurial 转换到 Git 是相当直接的,使用一个叫作“hg-fast-export”的工具,需要从这里拷贝一份:

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

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

[source,console]
----
$ hg clone <remote repo URL> /tmp/hg-repo
----

The next step is to create an author mapping file.
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.
Generating this is a one-line command in a `bash` shell:
下一步就是创建一个作者映射文件。
Mercurial 对放入到变更集作者字段的内容比 Git 更宽容一些,所以这是一个打扫屋子的好机会。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以这是一个打扫屋子的好机会——所以这是一个清理的好机会

生成映射是 `bash` 终端下的一行命令:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只需要用到 bash 终端下的一行命令


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

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:
这会花费几秒钟,具体要看项目提交历史有多少,最终 `/tmp/authors` 文件看起来会像这样:

[source]
----
Expand All @@ -37,10 +37,10 @@ Bob Jones <[email protected]>
Joe Smith <[email protected]>
----

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.
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.
If all the usernames look fine, we won't need this file at all.
In this example, we want our file to look like this:
在这个例子中,同一个人(Bob)使用不同的名字创建变更集,其中一个实际上是正确的,另一个完全不符合 Git 提交的规范。
Hg-fast-export 通过向我们想要修改的行尾添加 `={new name and email address}` 来修正这个问题,移除任何我们想要保留的用户名所在的行。
如果所有的用户名看起来都是正确的,那我们根本就不需要这个文件。
在本例中,我们会使文件看起来像这样:

[source]
----
Expand All @@ -50,7 +50,7 @@ bob jones <bob <AT> company <DOT> com>=Bob Jones <[email protected]>
bob <[email protected]>=Bob Jones <[email protected]>
----

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

[source,console]
----
Expand All @@ -59,9 +59,9 @@ $ cd /tmp/converted
$ /tmp/fast-export/hg-fast-export.sh -r /tmp/hg-repo -A /tmp/authors
----

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.
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).
This takes a bit (though it's _much_ faster than it would be over the network), and the output is fairly verbose:
`-r` 标记告诉 hg-fast-export 去哪里寻找我们想要转换的 Mercurial 仓库,`-A` 标记告诉它在哪找到作者映射文件。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的标记改成选项吧

这个脚本分析 Mercurial 变更集然后将它们转换成 Gitfast-import”功能(我们将在之后详细讨论)需要的脚本。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个脚本分析——这个脚本会分析

这会花一点时间(尽管它比通过网格 _更_ 快),输出相当的冗长:

[source,console]
----
Expand Down Expand Up @@ -109,9 +109,9 @@ $ git shortlog -sn
365 Joe Smith
----

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

[source,console]
----
Expand Down