Chapter 3
A tour of Mercurial: merging work

においてはリポジトリリポジトリでのチェンジセット生成ならびにhg pushおよびhg pullによるリポジトでのチェンジセット授受てきましたとしてリポジトリにおける mergeについててみましょう

3.1 Merging streams of work

においてです

じて実施するありふれたですのでMercurial ではえるようになっていますそれではきましょうもうリポジトリもうしましたよね?)、そのリポジトリにおいていま

1  $ cd ..
2  $ hg clone hello my-new-hello
3  updating working directory
4  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
5  $ cd my-new-hello
6  $ sed -i ’/printf/i∖∖tprintf("once more, hello.∖∖n");’ hello.c
7  $ hg commit -m ’A new hello for a new day.’

このなるつの hello.c コピするはずですつのリポジトリ 3.1 すようにかれしています

1  $ cat hello.c
2  /*
3   * Placed in the public domain by Bryan O’Sullivan.  This program is
4   * not covered by patents in the United States or other countries.
5   */
6  
7  #include <stdio.h>
8  
9  int main(int argc, char **argv)
10  {
11   printf("once more, hello.n");
12   printf("hello, world!");
13   return 0;
14  }
15  $ cat ../my-hello/hello.c
16  /*
17   * Placed in the public domain by Bryan O’Sullivan.  This program is
18   * not covered by patents in the United States or other countries.
19   */
20  
21  #include <stdio.h>
22  
23  int main(int argc, char **argv)
24  {
25   printf("hello, world!");
26   printf("hello again!n");
27   return 0;
28  }

[Picture]

Figure 3.1: Divergent recent histories of the my-hello and my-new-hello repositories

hg pullってもディレクトリにはぼさないことはしたとおりですのでmy-hello からhg pullしてみましょう

1  $ hg pull ../my-hello
2  pulling from ../my-hello
3  searching for changes
4  adding changesets
5  adding manifests
6  adding file changes
7  added 1 changesets with 1 changes to 1 files (+1 heads)
8  (run ’hg heads’ to see heads, ’hg merge’ to merge)

ディレクトリにはぼしていませんがhg pullコマンド“heads” についてしていま

3.1.1 Head changesets

“head” とはリポジトリにおいてないしとなるチェンジセットしないチェンジセットのことですリポジトリ におけるリビジョンチェンジセットちませんからって tip リビジョンhead となりますがつの ポジトリにはhead しえます



[Picture]

Figure 3.2: Repository contents after pulling from my-hello into my-new-hello

my-hello から my-new-hello へのhg pullによる 3.2 ることができますmy-new-hello していにはけられていませんがしいリビジョンされています  3.2 からはしいリポジトリmy-new-helloにおいてチェンジセットじままでもリビジョンなるれますそしてらずもチェンジセットにつ いてをするリビジョン使するのがくないというになっています)。hg headsコマンドによりリポジトリ head ることができます

1  $ hg heads
2  changeset:   6:30682a1ee732
3  tag:         tip
4  parent:      4:2278160e78d4
5  user:        Bryan O’Sullivan <bos@serpentine.com>
6  date:        Mon Jul 20 21:59:02 2009 +0000
7  summary:     Added an extra line of output
8  
9  changeset:   5:88c00c2c8751
10  user:        Bryan O’Sullivan <bos@serpentine.com>
11  date:        Mon Jul 20 21:59:07 2009 +0000
12  summary:     A new hello for a new day.
13  

3.1.2 Performing the merge

ディレクトリ、(my-hello からんだたな tip リビジョンするためにいつものようにhg updateコマ ンドするとどうなるでしょう

1  $ hg update
2  abort: crosses branches (use ’hg merge’ or ’hg update -C’)

Mercurial からhg updateコマンドではわれないされます実施われる をしないりはhg updateコマンドによるディレクトリわれませんhg updateコマンドわり hg mergeコマンドいてつの head します

1  $ hg merge
2  merging hello.c
3  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
4  (branch merge, don’t forget to commit)

[Picture]

Figure 3.3: Working directory and repository during merge, and following commit

hg mergeコマンドによってhg parentsコマンドおよび hello.c というhead ディレクトリされます

1  $ hg parents
2  changeset:   5:88c00c2c8751
3  user:        Bryan O’Sullivan <bos@serpentine.com>
4  date:        Mon Jul 20 21:59:07 2009 +0000
5  summary:     A new hello for a new day.
6  
7  changeset:   6:30682a1ee732
8  tag:         tip
9  parent:      4:2278160e78d4
10  user:        Bryan O’Sullivan <bos@serpentine.com>
11  date:        Mon Jul 20 21:59:02 2009 +0000
12  summary:     Added an extra line of output
13  
14  $ cat hello.c
15  /*
16   * Placed in the public domain by Bryan O’Sullivan.  This program is
17   * not covered by patents in the United States or other countries.
18   */
19  
20  #include <stdio.h>
21  
22  int main(int argc, char **argv)
23  {
24   printf("once more, hello.n");
25   printf("hello, world!");
26   printf("hello again!n");
27   return 0;
28  }

3.1.3 Committing the results of the merge

hg commitするまではhg parentsにはつのチェンジセットします

1  $ hg commit -m ’Merged changes’

これでしい tip リビジョンされましたしたつの head してくださいこれらは hg parentsしたリビジョンします

1  $ hg tip
2  changeset:   7:e947038a4c90
3  tag:         tip
4  parent:      5:88c00c2c8751
5  parent:      6:30682a1ee732
6  user:        Bryan O’Sullivan <bos@serpentine.com>
7  date:        Mon Jul 20 21:59:08 2009 +0000
8  summary:     Merged changes
9  

ディレクトリにどのようになっているのかそしてコミットによってどのようにリポジトリするのか  3.3 からることができますディレクトリであったつのチェンジセットコミットたなチェンジセットにとってのチェンジセットとなります

3.2 Merging conflicting changes

どのみますがにはチェンジセットファイルしているがあり ますければconflictじるためなる両立させてらかの れたにするためのです



[Picture]

Figure 3.4: Conflicting changes to a document

するつの 3.4 していますファイルにしていますがしてなるをしてしまいますするとはそのファイルがどのようになっているべ きかをすることになりません

Mercurial にはまれていませんそのわりにhgmerge ばれ プログラムしますこのプログラムMercurial されるシェルスクリプ 1 すがプログラムさせることもできますhgmerge ではつかのジツのう においてインストされているとわれるものをしますまずめにジツ 2 してみますが によってするがあるためにそれがしたそもそもそれらのされていないグラフィカルジツ みます3

HGMERGEプログラムないしスクリプトすることでMercurial hgmerge させるもでき ます

3.2.1 Using a graphical merge tool

のおめのグラフィカルジツkdiff3 なのでグラフィカルファイルマジツめられるについて れをしようといますイメ 3.2.1にありますしているつのファイルしてつのなる リビジョンすることから方法three-way mergeばれていますそれゆえジツウィン ドウつのしています

これらのされているのはでのですにおけるとはされ 6 ファイルとされるえることです

これらつのいにされているのでいずれかのスクロさせたには場所するよ うにされます



[Picture]

Figure 3.5: Using kdiff3 to merge versions of a file

ファイルにおいてするためにテキストそれらのわせめて選択することができますまたなるうためにすることもできま

ここでれないほどくのファイルマジツしますこれらはそれぞれプラットホ徴的 などのなりますどのテキストファイルしていますがにはファイルフォマット には XMLしたものもあります

3.2.2 A worked example

でのでは 3.4におけるファイル再現しますとなるファイルしたリポジトリすることから めましょう7

1  $ cat > letter.txt <<EOF
2  > Greetings!
3  > I am Mariam Abacha, the wife of former
4  > Nigerian dictator Sani Abacha.
5  > EOF
6  $ hg add letter.txt
7  $ hg commit -m ’419 scam, first draft’

リポジトリファイルします

1  $ cd ..
2  $ hg clone scam scam-cousin
3  updating working directory
4  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
5  $ cd scam-cousin
6  $ cat > letter.txt <<EOF
7  > Greetings!
8  > I am Shehu Musa Abacha, cousin to the former
9  > Nigerian dictator Sani Abacha.
10  > EOF
11  $ hg commit -m ’419 scam, with cousin’

もうリポジトリ利用によるファイルへの再現しますこのタスクごとに したリポジトリでのどころかそれらのすることですらしてしいことではないということを しています)。

1  $ cd ..
2  $ hg clone scam scam-son
3  updating working directory
4  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
5  $ cd scam-son
6  $ cat > letter.txt <<EOF
7  > Greetings!
8  > I am Alhaji Abba Abacha, son of the former
9  > Nigerian dictator Sani Abacha.
10  > EOF
11  $ hg commit -m ’419 scam, with son’

ファイルつのなるができたので実施いました

1  $ cd ..
2  $ hg clone scam-cousin scam-merge
3  updating working directory
4  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
5  $ cd scam-merge
6  $ hg pull -u ../scam-son
7  pulling from ../scam-son
8  searching for changes
9  adding changesets
10  adding manifests
11  adding file changes
12  added 1 changesets with 1 changes to 1 files (+1 heads)
13  not updating, since new heads added
14  (run ’hg heads’ to see heads, ’hg merge’ to merge)

における部分における refsec:automated-example-running ねるため では Mercurial hgmerge 使しませんそのわりにHGMERGE することでMercurial merge コマン させますこのコマンドくの Unix システムされています以下にはHGMERGE をわざわ するはありません

1  $ export HGMERGE=merge
2  $ hg merge
3  merging letter.txt
4  merge: warning: conflicts during merge
5  merging letter.txt failed!
6  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
7  use ’hg resolve’ to retry unresolved file merges or ’hg up --clean’ to abandon
8  $ cat letter.txt
9  Greetings!
10  <<<<<<< /tmp/tour-merge-conflictXc7qDZ/scam-merge/letter.txt
11  I am Shehu Musa Abacha, cousin to the former
12  =======
13  I am Alhaji Abba Abacha, son of the former
14  >>>>>>> /tmp/letter.txt~other.Fi_RTZ
15  Nigerian dictator Sani Abacha.

merge コマンドせずにどのにおけるしていてそのがどのチェンジセット由来するのかを ジマされたファイルみます

Mercurial merge8 するしますここでされる途中して しまったりってしまったことにいてグラフィカルジツ中途させたなどにちま

ないししたであってもファイルしたコミットすること です

1  $ cat > letter.txt <<EOF
2  > Greetings!
3  > I am Bryan O’Sullivan, no relation of the former
4  > Nigerian dictator Sani Abacha.
5  > EOF
6  $ hg commit -m ’Send me your money’
7  abort: unresolved merge conflicts (see hg resolve)
8  $ hg tip
9  changeset:   2:ad1a49b7184f
10  tag:         tip
11  parent:      0:ac90448432c1
12  user:        Bryan O’Sullivan <bos@serpentine.com>
13  date:        Mon Jul 20 21:59:09 2009 +0000
14  summary:     419 scam, with son
15  

3.3 Simplifying the pull-merge-commit sequence

ここまでにべてきたなものですがつのコマンドするがあります

1  hg pull
2  hg merge
3  hg commit -m ’Merged remote changes’

最後コミットにはくもまりきったにならざるをませんがコミットメッセする があります

であればとされるさせたいものですMercurial これをとするfetchばれるイクステン ションされています

Mercurial いの便性上から核機さくにするための イクステンションしていますコマンドラインから利用できる Mercurial コマンドする イクステンションもあればえばするようなするイクステンションもありま

fetch イクステンションしたこととはいますがhg fetchばれるしいコマンドしますhg fetch マンドhg pullhg updatehg mergehg commitわせのようにいますまずは ポジトリからリポジトリみますんだチェンジセットによるたな head 9 された 生成されたコミットメッセ使ってコミットいますたな head かった hg fetchコマンドディレクトリtip リビジョンします

fetch イクステンションできます.hgrc ファイル[extensions] セクションしてく ださいfetch まるします

1  [extensions]
2  fetch =

=イクステンションしますがfetch イクステンション布物されているので Mercurial fetch すことができます