|
2 | 2 | ==== TFS
|
3 | 3 |
|
4 | 4 | (((TFS)))(((Importing, from TFS)))
|
5 |
| -If your team is converting their source control from TFVC to Git, you'll want the highest-fidelity conversion you can get. |
6 |
| -This means that, while we covered both git-tfs and git-tf for the interop section, we'll only be covering git-tfs for this part, because git-tfs supports branches, and this is prohibitively difficult using git-tf. |
| 5 | +如果你的团队正在将他们的源代码管理从 TFVC 转换为 Git,你们会想要最高程度的无损转换。 |
| 6 | +这意味着,虽然我们在之前的交互章节介绍了 git-tfs 与 git-tf 两种工具,但是我们在本部分只能介绍 git-tfs,因为 git-tfs 支持分支,而使用 git-tf 代价太大。 |
7 | 7 |
|
8 | 8 | [NOTE]
|
9 | 9 | ====
|
10 |
| -This is a one-way conversion. |
11 |
| -The resulting Git repository won't be able to connect with the original TFVC project. |
| 10 | +这是一个单向转换。 |
| 11 | +这意味着 Git 仓库无法连接到原始的 TFVC 项目。 |
12 | 12 | ====
|
13 | 13 |
|
14 |
| -The first thing to do is map usernames. |
15 |
| -TFVC is fairly liberal with what goes into the author field for changesets, but Git wants a human-readable name and email address. |
16 |
| -You can get this information from the `tf` command-line client, like so: |
| 14 | +第一件事是映射用户名。 |
| 15 | +TFVC 对待变更集作者字段的内容相当宽容,但是 Git 需要人类可读的名字与邮箱地址。 |
| 16 | +可以通过 `tf` 命令行客户端来获取这个信息,像这样: |
17 | 17 |
|
18 | 18 | [source,powershell]
|
19 | 19 | ----
|
20 | 20 | PS> tf history $/myproject -recursive > AUTHORS_TMP
|
21 | 21 | ----
|
22 | 22 |
|
23 |
| -This grabs all of the changesets in the history of the project and put it in the AUTHORS_TMP file that we will process to extract the data of the 'User' column (the 2nd one). |
24 |
| -Open the file and find at which characters start and end the column and replace, in the following command-line, the parameters `11-20` of the `cut` command with the ones found: |
| 23 | +这会将历史中的所有变更集抓取下来并放到 AUTHORS_TMP 文件中,然后我们将会将 `User` 列(第二个)取出来。 |
| 24 | +打开文件找到列开始与结束的字符并替换,在下面的命令行中,`cut` 命令的参数 `11-20` 就是我们找到的: |
25 | 25 |
|
26 | 26 | [source,powershell]
|
27 | 27 | ----
|
28 | 28 | PS> cat AUTHORS_TMP | cut -b 11-20 | tail -n+3 | uniq | sort > AUTHORS
|
29 | 29 | ----
|
30 | 30 |
|
31 |
| -The `cut` command keeps only the characters between 11 and 20 from each line. |
32 |
| -The `tail` command skips the first two lines, which are field headers and ASCII-art underlines. |
33 |
| -The result of all of this is piped to `uniq` to eliminate duplicates, and saved to a file named `AUTHORS`. |
34 |
| -The next step is manual; in order for git-tfs to make effective use of this file, each line must be in this format: |
| 31 | +`cut` 命令只会保留每行中第 11 个到第 22 个字符。 |
| 32 | +`tail` 命令会跳过前两行,就是字段表头与 ASCII 风格的下划线。 |
| 33 | +所有这些的结果通过管道送到 `uniq` 来去除重复,然后保存到 `AUTOHRS` 文件中。 |
| 34 | +下一步是手动的;为了让 git-tfs 有效地使用这个文件,每一行必须是这种格式: |
35 | 35 |
|
36 | 36 | [source,text]
|
37 | 37 | ----
|
38 | 38 | DOMAIN\username = User Name <[email protected]>
|
39 | 39 | ----
|
40 | 40 |
|
41 |
| -The portion on the left is the ``User'' field from TFVC, and the portion on the right side of the equals sign is the user name that will be used for Git commits. |
| 41 | +左边的部分是 TFVC 中的 ``User'' 字段,等号右边的部分是将被用作 Git 提交的用户名。 |
42 | 42 |
|
43 |
| -Once you have this file, the next thing to do is make a full clone of the TFVC project you're interested in: |
| 43 | +一旦有了这个文件,下一件事就是生成一个你需要的 TFVC 项目的完整克隆: |
44 | 44 |
|
45 | 45 | [source,powershell]
|
46 | 46 | ----
|
47 | 47 | PS> git tfs clone --with-branches --authors=AUTHORS https://username.visualstudio.com/DefaultCollection $/project/Trunk project_git
|
48 | 48 | ----
|
49 | 49 |
|
50 |
| -Next you'll want to clean the `git-tfs-id` sections from the bottom of the commit messages. |
51 |
| -The following command will do that: |
| 50 | +接下来要从提交信息底部清理 `git-tfs-id` 区块。 |
| 51 | +下面的命令会完成这个任务: |
52 | 52 |
|
53 | 53 | [source,powershell]
|
54 | 54 | ----
|
55 | 55 | PS> git filter-branch -f --msg-filter 'sed "s/^git-tfs-id:.*$//g"' -- --all
|
56 | 56 | ----
|
57 | 57 |
|
58 |
| -That uses the `sed` command from the Git-bash environment to replace any line starting with ``git-tfs-id:'' with emptiness, which Git will then ignore. |
| 58 | +那会使用 Git 终端环境中的 `sed` 命令来将所有以 ``git-tfs-id:'' 开头的行替换为 Git 会忽略的空白。 |
59 | 59 |
|
60 |
| -Once that's all done, you're ready to add a new remote, push all your branches up, and have your team start working from Git. |
| 60 | +全部完成后,你就已经准备好去增加一个新的远程仓库,推送你所有的分支上去,然后你的团队就可以开始用 Git 工作了。 |
0 commit comments