Skip to content

Translate 09-git-and-other-scms import-svn v2 #180

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

Merged
merged 21 commits into from
Aug 12, 2015
Merged
Changes from all 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
60 changes: 30 additions & 30 deletions book/09-git-and-other-scms/sections/import-svn.asc
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@

(((Subversion)))
(((Importing, from Subversion)))
If you read the previous section about using `git svn`, you can easily use those instructions to `git svn clone` a repository; then, stop using the Subversion server, push to a new Git server, and start using that.
If you want the history, you can accomplish that as quickly as you can pull the data out of the Subversion server (which may take a while).
如果你阅读过前面关于 `git svn` 的章节,可以轻松地使用那些指令来 `git svn clone` 一个仓库,停止使用 Subversion 服务器,推送到一个新的 Git 服务器,然后就可以开始使用了。
如果你想要历史,可以从 Subversion 服务器上尽可能快地拉取数据来完成这件事(这可能会花费一些时间)。

However, the import isn't perfect; and because it will take so long, you may as well do it right.
The first problem is the author information.
In Subversion, each person committing has a user on the system who is recorded in the commit information.
The examples in the previous section show `schacon` in some places, such as the `blame` output and the `git svn log`.
If you want to map this to better Git author data, you need a mapping from the Subversion users to the Git authors.
Create a file called `users.txt` that has this mapping in a format like this:
然而,导入并不完美;因为花费太长时间了,你可能早已用其他方法完成导入操作。
导入产生的第一个问题就是作者信息。
Subversion 中,每一个人提交时都需要在系统中有一个用户,它会被记录在提交信息内。
在之前章节的例子中几个地方显示了 `schacon`,比如 `blame` 输出与 `git svn log`
如果想要将上面的 Subversion 用户映射到一个更好的 Git 作者数据中,你需要一个 Subversion 用户到 Git 用户的映射。
创建一个 `users.txt` 的文件包含像下面这种格式的映射:

[source]
----
schacon = Scott Chacon <schacon@geemail.com>
selse = Someo Nelse <selse@geemail.com>
----

To get a list of the author names that SVN uses, you can run this:
为了获得 SVN 使用的作者名字列表,可以运行这个:
Copy link

Choose a reason for hiding this comment

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

为了获得 使用SVN 的作者名字列表

Copy link
Member Author

Choose a reason for hiding this comment

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

这个地方是 SVN 用的,所以保留原文。


[source,console]
----
$ svn log --xml | grep author | sort -u | \
perl -pe 's/.*>(.*?)<.*/$1 = /'
----

That generates the log output in XML format, then keeps only the lines with author information, discards duplicates, strips out the XML tags.
(Obviously this only works on a machine with `grep`, `sort`, and `perl` installed.)
Then, redirect that output into your users.txt file so you can add the equivalent Git user data next to each entry.
这会将日志输出为 XML 格式,然后保留作者信息行、去除重复、去除 XML 标记。
(很显然这只会在安装了 `grep``sort` `perl` 的机器上运行。)
然后,将输出重定向到你的 users.txt 文件中,这样就可以在每一个记录后面加入对应的 Git 用户数据。

You can provide this file to `git svn` to help it map the author data more accurately.
You can also tell `git svn` not to include the metadata that Subversion normally imports, by passing `--no-metadata` to the `clone` or `init` command.
This makes your `import` command look like this:
你可以将此文件提供给 `git svn` 来帮助它更加精确地映射作者数据。
也可以通过传递 `--no-metadata` `clone` `init` 命令,告诉 `git svn` 不要包括 Subversion 通常会导入的元数据。
这会使你的 `import` 命令看起来像这样:

[source,console]
----
$ git svn clone http://my-project.googlecode.com/svn/ \
--authors-file=users.txt --no-metadata -s my_project
----

Now you should have a nicer Subversion import in your `my_project` directory.
Instead of commits that look like this
现在在 `my_project` 目录中应当有了一个更好的 Subversion 导入。
并不像是下面这样的提交:

[source]
----
Expand All @@ -55,7 +55,7 @@ Date: Sun May 3 00:12:22 2009 +0000
be05-5f7a86268029
----

they look like this:
反而它们看起来像是这样:

[source]
----
Expand All @@ -66,44 +66,44 @@ Date: Sun May 3 00:12:22 2009 +0000
fixed install - go to trunk
----

Not only does the Author field look a lot better, but the `git-svn-id` is no longer there, either.
不仅是 Author 字段更好看了,`git-svn-id` 也不在了。

You should also do a bit of post-import cleanup.
For one thing, you should clean up the weird references that `git svn` set up.
First you'll move the tags so they're actual tags rather than strange remote branches, and then you'll move the rest of the branches so they're local.
之后,你应当做一些导入后的清理工作。
第一步,你应当清理 `git svn` 设置的奇怪的引用。
首先移动标签,这样它们就是标签而不是奇怪的远程引用,然后你会移动剩余的分支这样它们就是本地的了。

To move the tags to be proper Git tags, run
为了将标签变为合适的 Git 标签,运行

[source,console]
----
$ cp -Rf .git/refs/remotes/origin/tags/* .git/refs/tags/
$ rm -Rf .git/refs/remotes/origin/tags
----

This takes the references that were remote branches that started with `remotes/origin/tags/` and makes them real (lightweight) tags.
这会使原来在 `remotes/origin/tags/` 里的远程分支引用变成真正的(轻量)标签。

Next, move the rest of the references under `refs/remotes` to be local branches:
接下来,将 `refs/remotes` 下剩余的引用移动为本地分支:

[source,console]
----
$ cp -Rf .git/refs/remotes/* .git/refs/heads/
$ rm -Rf .git/refs/remotes
----

Now all the old branches are real Git branches and all the old tags are real Git tags.
The last thing to do is add your new Git server as a remote and push to it.
Here is an example of adding your server as a remote:
现在所有的旧分支都是真正的 Git 分支,并且所有的旧标签都是真正的 Git 标签。
最后一件要做的事情是,将你的新 Git 服务器添加为远程仓库并推送到上面。
下面是一个将你的服务器添加为远程仓库的例子:

[source,console]
----
$ git remote add origin git@my-git-server:myrepository.git
----

Because you want all your branches and tags to go up, you can now run this:
因为想要上传所有分支与标签,你现在可以运行:

[source,console]
----
$ git push origin --all
----

All your branches and tags should be on your new Git server in a nice, clean import.
通过以上漂亮、干净地导入操作,你的所有分支与标签都应该在新 Git 服务器上。