## 教程 - 合并改變
在 [《教程 - 和別人分享改變》](/wiki/ChineseTutorialShareChange)一節, 我們學會了如何與其他人共享變更. 但是因為(0.7 版本開始) [Import](/wiki/Import) 不能正確的處理通過郵件發送的合并, 我們要演示如何從其他做了不兼容變更的倉庫用拖合并。
首先, 我們必須創建合并的目標. 我們再次 [Clone](/wiki/Clone) `my-hello`的倉庫:
```
$ cd ..
$ hg clone my-hello my-hello-desc
```
我們給 `hello.c` 的注釋段加一段描述.
```
$ cd my-hello-desc
$ vi hello.c
```
我們將第二行:
```
* hello.c
```
改為:
```
* hello.c - hello, world
```
我們存檔并退出編輯器, 然后 [Commit](/wiki/Commit) 我們的變更. 這次, 我們在`commit`命令中使用`-m` 選項來節省時間, 以免我們又要進入編輯器:
```
$ hg commit -m 'Add description of hello.c'
```
這時, 我們已經對 `my-hello-new-output` [倉庫](/wiki/Repository)中的 `hello.c` 作了一個變更 , 同時對 `my-hello-desc` [倉庫](/wiki/Repository) 中的 `hello.c` 作了另一個變更. 我們怎樣 _merge_ 這兩個分叉開發主線? 我們從一個倉庫拖進另外一個倉庫的時候會出現問題嗎?
這完全沒有問題. 現在仍然在 `my-hello-desc`中, 我們從 `my-hello-new-output`中 [Pull](/wiki/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)
```
這看起來像 [TutorialShareChange](/wiki/TutorialShareChange)! 中 `pull` 的輸出,所以我們現在要進行[Update](/wiki/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)
```
噢,好像發生了什么事情. [Mercurial](/wiki/ChineseMercurial) 告訴我們必須 [Merge](/wiki/Merge)每個 [倉庫](/wiki/Repository) 中的變更. 看起來有點麻煩, 對嗎? 其實很簡單. 現在我們按照輸出最后一行的指令執行:
```
$ hg merge
merging hello.c
```
這就完成了! 通過調用`hgmerge`腳本(或者你自己定義的合并程序),[Mercurial](/wiki/ChineseMercurial)可以自動的替你完成合并. Depending on your environment, the `hgmerge` may call a graphical merge resolver tool. If we look at `hello.c`, we find that it contains _both_ the change from `my-hello-new-output` and the change from `my-hello-desc`.
(注意:在Mercurial 0.9版之前,因該使用`hg?update?-m`替代`hg?merge`).
當合并他人所做的修改時,大部分時間都是這種還算容易應付的合并方式。
恩,讓我們繼續去學習如何處理沖突性變更的情況,這部分將在[合并有沖突的改變](/wiki/ChineseTutorialConflict)中介紹。