Differences between revisions 2 and 11 (spanning 9 versions)
Revision 2 as of 2006-12-10 16:03:06
Size: 5598
Editor: pc156
Comment:
Revision 11 as of 2009-05-20 09:21:42
Size: 3388
Comment: Fix another link.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#language zh
Line 3: Line 5:
We learned how to deal with simple ["Merge"]s in TutorialMerge. 在[[ChineseTutorialMerge|合并]]中我们已经学会了如何处理简单的[[Merge]]。
Line 5: Line 7:
在TutoialMerge中我们已经学会了如何处理简单的合并. [[Mercurial]]当然也处理更加复杂的 [[Merge]]。很平常的情况是两个人同时更改同一个文件的同一段代码,然后必须给出处理的方法。这称之为冲突;处理这类冲突称之为合并。
Line 7: Line 9:
["mercurial"]当然也处理更加复杂的合并。很平常的情况是两个人同时更改同一个文件的同一段代码,然后必须给出处理的方法。这称之为冲突;处理这类冲突称之为合并。

["Mercurial"] handles more complex ["Merge"] cases, too. It is not all that uncommon for two people to edit the exact same lines of a file, and then have to figure out what to do. These cases are called conflicts; figuring out what to do about a conflict is called resolving it.

首先让我们人为的创建一个冲突的实例。 正如我们前面所做的, 通过做一个{{my-hello}}的克隆开始:

Let's first create an artificial conflict situation. As we did previously, let's start by making a ["Clone"] of {{{my-hello}}}:
首先让我们人为的创建一个冲突的实例。 正如我们前面所做的, 通过做一个{{{my-hello}}}的[[Clone]]开始:
Line 22: Line 18:
Now let's add a new line of output to {{{hello.c}}}:
Line 29: Line 23:
改变{{main}}如下所示:
We change {{{main}}} to read like this:
改变 {{{main}}} 如下所示:
Line 41: Line 34:
然后提交这些改变:
And we ["Commit"] the change:
然后 [[Commit]] 这些改变:
Line 48: Line 40:
正如TuroialFirstChange那样,我们在{{{my-hello-new-output}}}里建立了一个ChangeSet,{{{my-hello-new-output}}}包含了第二输出行。如果这时我们使用["Pull"]指令时,会发生什么事情呢?

Recall that in TutorialFirstChange, we created a ChangeSet in {{{my-hello-new-output}}} that ''also'' added a second line of output. What happens when we try to ["Pull"] that change in here?
正如[[ChineseTutorialFirstChange|第一次改变]]那样,我们在{{{my-hello-new-output}}}里建立了一个[[ChangeSet|变更集]],{{{my-hello-new-output}}}包含了第二输出行。如果这时我们使用[[Pull]]指令时,会发生什么事情呢?
Line 63: Line 53:
到目前为止,非常顺利。 让我们试试["Update"].
So far, so good. Let's try an ["Update"
].
到目前为止,非常顺利。 让我们试试 [[Update]]
Line 74: Line 63:
正如TutorialMerge那样,我们不得不运行 {{{hg merge}}}. 像往前一样, 合并程序将被启动。经常是不能自动合并,因为同样源文件的相同的代码在每个ChangeSet中被不同的方式更改(一个是我们提交的更改方式,一个是我们["Pull"]来的)。

As in TutorialMerge, we have to run {{{hg merge}}}. As before,
the MergeProgram will be started under cover. It will usually not be able to ["Merge"] automatically, because the same line of the same source file has been modified in a different way by each ChangeSet (the one we just ["Commit"]ted, and the one we just ["Pull"]ed).
正如[[ChineseTutorialMerge|合并]]那样,我们不得不运行 {{{hg merge}}}. 像往前一样, 合并程序将被启动。经常是不能自动合并,因为同样源文件的相同的代码在每个ChangeSet中被不同的方式更改(一个是我们提交的更改方式,一个是我们[Pull]来的)。
Line 85: Line 71:
At this point, what happens depends on what programs are installed on our computer. If we are provident or lucky, and have a graphical MergeProgram installed, we will be able to see what conflicts there are between the two changes, and decide how to resolve them. [[Mercurial]] 使用了三路合并。 这就意味着有三个文件来做合并,分别是:
 *本地文件(当前仓库)
 *其它文件(正在被合并的仓库)
 *基文件 (在分支分开前的最后一个版本)
Line 87: Line 76:
["Mercurial" 使用了三路合并。 这就意味着有三个文件来做合并,分别是:
*本地文件(当前仓库)
*其它文件(正在被合并的仓库)
*基文件 (在分支分开前的最后一个版本)
要了解更多的三路合并, 请参考[[http://revctrl.org/ThreeWayMerge|ThreeWayMerge]] on the [[http://revctrl.org/|Revctrl wiki]].
Line 92: Line 78:
["Mercurial"] is using a per-file 3-way merge. This means that there are 3 input files for merging process, and those are:
 * Local file (from current repository)
 * Other file (from repository being merged)
 * Base file (last version of file before branches separated)
另外,如果我们没有安装图形合并程序, 我们就会开启文本编辑器来访问需要合并的文件。用手工来做这些事情是'''非常'''容易出错并且繁琐的。 最好是退出编辑器并用{{{hg rollback}}}指令来清除["Pull"]带来的改变,然后安装合并程序,再做一次。
Line 97: Line 80:
要了解更多的3-way, 请参考[http://revctrl.org/ThreeWayMerge ThreeWayMerge] on the [http://revctrl.org/ Revctrl wiki].

For more information about 3-way, see [http://revctrl.org/ThreeWayMerge ThreeWayMerge] on the [http://revctrl.org/ Revctrl wiki].

另外,如果我们没有安装图形合并程序, 我们就会开启文本编辑器来访问需要合并的文件。用手工来做这些事情是非常容易出错并且繁琐的。 最好是退出编辑器并用{{{hg rollback}}}指令来清除[“Pull"]带来的改变,然后安装合并程序,再做一次。

Else, if we do not have a graphical MergeProgram installed, we will be dropped into a text editor, which will be visiting the file we need to ["Merge"]. Doing this by hand is '''highly''' error-prone and tedious. It is best to exit the editor and use the {{{hg rollback}}} command to reverse the effect of the ["Pull"], then install a MergeProgram, and then try again.

(~:注意: 0.9之前的版本, “hg merge"必须使用"hg update -m"代替, "hg rollback"必须用"hg undo"代替。

(~-Note: before Mercurial version 0.9, `hg update -m` should have been used in place of `hg merge` and `hg undo` should have been used instead of `hg rollback`-~).
(~-注意: Mercurial 0.9之前的版本,"hg merge" 必须使用 "hg update -m"代替,"hg rollback" 必须用 "hg undo" 代替。)
Line 110: Line 83:
Now let's continue and finish on to ChineseTutorialConclusion. 现在让我们继续并在[[ChineseTutorialConclusion|总结]]中完成我们的教程。
----
CategoryChinese

教程 - 合并有冲突的改变

合并中我们已经学会了如何处理简单的Merge

Mercurial当然也处理更加复杂的 Merge。很平常的情况是两个人同时更改同一个文件的同一段代码,然后必须给出处理的方法。这称之为冲突;处理这类冲突称之为合并。

首先让我们人为的创建一个冲突的实例。 正如我们前面所做的, 通过做一个my-helloClone开始:

$ cd ..
$ hg clone my-hello my-hello-not-cvs

现在,加入一些新的输出语句到hello.c:

$ cd my-hello-not-cvs
$ vi hello.c

改变 main 如下所示:

int main(int argc, char **argv)
{
        printf("hello, world!\n");
        printf("sure am glad I'm not using CVS!\n");
        return 0;
}

然后 Commit 这些改变:

$ hg commit -m 'Give thanks for dodging bullet'

正如第一次改变那样,我们在my-hello-new-output里建立了一个变更集my-hello-new-output包含了第二输出行。如果这时我们使用Pull指令时,会发生什么事情呢?

$ hg pull ../my-hello-new-output
pulling from ../my-hello-new-output
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg update' to get a working copy)

到目前为止,非常顺利。 让我们试试 Update

$ hg update
this update spans a branch affecting the following files:
 hello.c (resolve)
aborting update spanning branches!
(use 'hg merge' to merge across branches or 'hg update -C' to lose changes)

正如合并那样,我们不得不运行 hg merge. 像往前一样, 合并程序将被启动。经常是不能自动合并,因为同样源文件的相同的代码在每个ChangeSet中被不同的方式更改(一个是我们提交的更改方式,一个是我们[Pull]来的)。

$ hg merge

这时,会发生什么决定于电脑中安装了什么样的程序。 如果我们有先见之明或者幸运的话, 并且安装了图形的合并程序,我们就能够看到在两个更改之间发生了什么冲突,并决定如何去做。

Mercurial 使用了三路合并。 这就意味着有三个文件来做合并,分别是:

  • 本地文件(当前仓库)
  • 其它文件(正在被合并的仓库)
  • 基文件 (在分支分开前的最后一个版本)

要了解更多的三路合并, 请参考ThreeWayMerge on the Revctrl wiki.

另外,如果我们没有安装图形合并程序, 我们就会开启文本编辑器来访问需要合并的文件。用手工来做这些事情是非常容易出错并且繁琐的。 最好是退出编辑器并用hg rollback指令来清除["Pull"]带来的改变,然后安装合并程序,再做一次。

(注意: Mercurial 0.9之前的版本,"hg merge" 必须使用 "hg update -m"代替,"hg rollback" 必须用 "hg undo" 代替。)

现在让我们继续并在总结中完成我们的教程。


CategoryChinese

ChineseTutorialConflict (last edited 2009-05-20 09:21:42 by DirkjanOchtman)