Chapter 2
A tour of Mercurial: the basics

2.1 Installing Mercurial on your system

ての OS けにビルドみの Mercurial バイナリされていますバイナリ使することで Mercurial セットアップすることができます

2.1.1 Linux

Linux ディストリビュションそれぞれパッケパッケならびにっていますのてのバイナリ Mercurial インストするうのはですまたバイナリインストよって利用 Mercurial ジョンディストリビュションパッケどの程度であるかによっなります

便のためLinux ディストリビュションにおけるコマンドラインいた Mercurial インストしてしますどのディストリビュションでは mercurial というパッケしたならばリックひとつで Mercurial インストできるようなグラフィカルパッケされていま

Debian
1  apt-get install mercurial
Fedora Core
1  yum install mercurial
Gentoo
1  emerge mercurial
OpenSUSE
1  yum install mercurial
Ubuntu
Ubuntu Mercurial パッケいので使すべきではありませんできればDebian パッケリビルドしてインストしてくださいおそらく Mercurial からビルドするでしょうそのA.1  してください

2.1.2 Mac OS X

Mac OS X けの Mercurial インストLee Cantey によってhttp://mercurial.berkwood.com されていますこの パッケIntel および Power Mac しますこのインスト使するUniversal MacPython [BI] のある Python インストするがありますLee サイトにあるめばインストできま

2.1.3 Solaris

XXX

2.1.4 Windows

Windows けの Mercurial インストLee Cantey によってhttp://mercurial.berkwood.com されていますこの パッケパッケへのがありませんので利用できます

: Windows Mercurial Windows Unix いませんUnix 利用したい がありますXXX

2.2 Getting started

Mercurial 使めるにあたり利用Mercurial コマンドジョンするためhg versionコマンド 使ってみましょうジョンにはそれほどはありませんがされない

1  $ hg version
2  Mercurial Distributed SCM (version 1.3)
3  
4  Copyright (C) 2005-2009 Matt Mackall <mpm@selenic.com> and others
5  This is free software; see the source for copying conditions. There is NO
6  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2.2.1 Built-in help

Mercurial ヘルプっていますこのコマンド方法せない有用ですをしていのか にわからなくなってしまったhg helpすることでそれぞれがどのようなっているかの コマンドされます以下すようなコマンドについてhg helpしたそのコマン するされます

1   $ hg help init
2  hg init [-e CMD] [--remotecmd CMD] [DEST]
3  
4  create a new repository in the given directory
5  
6      Initialize a new repository in the given directory. If the given
7      directory does not exist, it will be created.
8  
9      If no directory is given, the current directory is used.
10  
11      It is possible to specify an ssh:// URL as the destination.
12      See ’hg help urls’ for more information.
13  
14  options:
15  
16   -e --ssh        specify ssh command to use
17      --remotecmd  specify hg command to run on the remote side
18  
19  use "hg -v help init" to show global options

くのとしないするにはhg help -vします-v オプション--verbose よりもくのMercurial させます

2.3 Working with a repository

Mercurial ではてがリポジトリじていますえばあるプロジェクトのためにしたリポジトリにはプロジェクト するてのファイルだけでなくファイルするされています

リポジトリファイルシステムにあるディレクトリツリですのでMercurial いするということには ディレクトリファイルしてわっているはありませんコマンドファイルブラウザ利用して することができます

2.3.1 Making a local copy of a repository

リポジトリですディレクトリコマンドでもリポジトリできますがMercurial みの コマンド使したいでしょこのコマンドリポジトリ生成するためhg cloneばれていま

1  $ hg clone http://hg.serpentine.com/tutorial/hello
2  destination directory: hello
3  requesting all changes
4  adding changesets
5  adding manifests
6  adding file changes
7  added 5 changesets with 5 changes to 2 files
8  updating working directory
9  2 files updated, 0 files merged, 0 files removed, 0 files unresolved

チュトリアルリポジトリからのしたならカルファイルシステムhello というディレクトリがある ですこのディレクトリにはファイルつかされていることでしょうThis directory will contain some files.

1  $ ls -l
2  total 4
3  drwxr-xr-x 3 vmuser vmuser 4096 Jul 20 21:59 hello
4  $ ls hello
5  Makefile  hello.c

これらのファイルになったリポジトリにおけるファイルっています

ての Mercurial リポジトリなものをしているためそれしているしたです ポジトリにはプロジェクトするファイルされますされたリポジトリとなったリポ ジトリしていますが指示をしないリポジトリとのおよびそれリポジトリとの われません

それぞれのリポジトリリポジトリぼすことのえますからリポジトリ ができるわけです

2.3.2 What’s in a repository?

リポジトリてみると.hg というディレクトリがあることにくことでしょうこのディレクトリ Mercurial リポジトリメタデしているディレクトリです

1  $ cd hello
2  $ ls -a
3  .  ..  .hg  Makefile  hello.c

.hg およびそのディレクトリMercurial 使するものですリポジトリにおけるそれディレクト ファイル利用していません

をするにあたり.hg ディレクトリリポジトリとするならそれとするファイルディレクトリ ディレクトリにあるものばれますうならリポジトリプロジェクトする ディレクトリのとあるにおけるプロジェクトスナップショットするえま

2.4 A tour through history

みのしいリポジトリしてはまずはそのしてみようとうことでしょうhg logコマンド します

1  $ hg log
2  changeset:   4:2278160e78d4
3  tag:         tip
4  user:        Bryan O’Sullivan <bos@serpentine.com>
5  date:        Sat Aug 16 22:16:53 2008 +0200
6  summary:     Trim comments.
7  
8  changeset:   3:0272e0d5a517
9  user:        Bryan O’Sullivan <bos@serpentine.com>
10  date:        Sat Aug 16 22:08:02 2008 +0200
11  summary:     Get make to generate the final binary from a .o file.
12  
13  changeset:   2:fef857204a0c
14  user:        Bryan O’Sullivan <bos@serpentine.com>
15  date:        Sat Aug 16 22:05:04 2008 +0200
16  summary:     Introduce a typo into hello.c.
17  
18  changeset:   1:82e55d328c8c
19  user:        mpm@selenic.com
20  date:        Fri Aug 26 01:21:28 2005 -0700
21  summary:     Create a makefile
22  
23  changeset:   0:0a04b987be5a
24  user:        mpm@selenic.com
25  date:        Fri Aug 26 01:20:50 2005 -0700
26  summary:     Create a standard "hello, world" program
27  

このコマンドではプロジェクトえられたしていますMercurial ではファイルするることからされたこれらのチェンジセットしま

hg logにおける以下のようになっています

changeset
この10 進数コロンcolon: :および 16 進数となっていますつのチェンジ セットです16 進数のものよりも10 進数であることからつの ます
user
チェンジセットするですこのですがどのルアドレス されます
date
チェンジセットされたそのタイムゾですタイムゾにおけるですのでチェンジ セットにとってのします)。
summary
チェンジセットチェンジセットとしてしたメッセです

におけるhg log要約ですのでくのけています

 2.4 くするためにhello リポジトリにおけるしたものですおよびにお いてかこのることになることでしょう



[Picture]

Figure 2.1: Graphical history of the hello repository

2.4.1 Changesets, revisions, and talking to other people

さで言語でありでははいつものことですのでではじことを しがしますMercurial でのについてをするチェンジセットchangesetという には チェンジchange“cset” などとされていたりチェンジセットという しがリビジョンrevisionないし “rev” すものとして使されたりするのをにするかもしれませ

チェンジセットをどのようなそうがではありませんがチェンジセットすための ですhg logにおける changeset 10 進数16 進数使ってチェンジセットしてい ということをしてください

このですリビジョン 33” をしたリビジョン 33 するそれとは なりますこれはリビジョンけがチェンジセットリポジトリされた順序しており チェンジセット順序であることをなるリポジトリではできないためですつのチェンジセット a,b,c とあるリポジトリでは 0,1,2 順序されるリポジトリでは 1,0,2 順序されるといったことは ます

Mercurial リビジョン使しているのは純粋便のためですチェンジセットしてをす らかのえばにおけるによってチェンジセットする16 進数使 いましょう

2.4.2 Viewing specific revisions

hg logリビジョンのものにする-rないし--revオプション使します10 進数リビジョン 16 進数チェンジセットのどちらも使できますしじてリビジョンすることもできま

1  $ hg log -r 3
2  changeset:   3:0272e0d5a517
3  user:        Bryan O’Sullivan <bos@serpentine.com>
4  date:        Sat Aug 16 22:08:02 2008 +0200
5  summary:     Get make to generate the final binary from a .o file.
6  
7  $ hg log -r ff5d7b70a2a9
8  abort: unknown revision ’ff5d7b70a2a9’!
9  $ hg log -r 1 -r 4
10  changeset:   1:82e55d328c8c
11  user:        mpm@selenic.com
12  date:        Fri Aug 26 01:21:28 2005 -0700
13  summary:     Create a makefile
14  
15  changeset:   4:2278160e78d4
16  tag:         tip
17  user:        Bryan O’Sullivan <bos@serpentine.com>
18  date:        Sat Aug 16 22:16:53 2008 +0200
19  summary:     Trim comments.
20  

することしにリビジョンしたい使しますこのa から b てのリビジョンというします

1  $ hg log -r 2:4
2  changeset:   2:fef857204a0c
3  user:        Bryan O’Sullivan <bos@serpentine.com>
4  date:        Sat Aug 16 22:05:04 2008 +0200
5  summary:     Introduce a typo into hello.c.
6  
7  changeset:   3:0272e0d5a517
8  user:        Bryan O’Sullivan <bos@serpentine.com>
9  date:        Sat Aug 16 22:08:02 2008 +0200
10  summary:     Get make to generate the final binary from a .o file.
11  
12  changeset:   4:2278160e78d4
13  tag:         tip
14  user:        Bryan O’Sullivan <bos@serpentine.com>
15  date:        Sat Aug 16 22:16:53 2008 +0200
16  summary:     Trim comments.
17  

Mercurial はりビジョン順序いますのでhg log -r 2:4というコマンド2,3,4 順序する hg log -r 4:2というコマンド4,3,2 順序します

2.4.3 More detailed information

てのチェンジセットしているhg logする有用ですがあるチェンジセット のものかかをしようとするにはについてのされたファイルにな ることでしょうhg logコマンド-vないし--verboseオプションこれらしま

1  $ hg log -v -r 3
2  changeset:   3:0272e0d5a517
3  user:        Bryan O’Sullivan <bos@serpentine.com>
4  date:        Sat Aug 16 22:08:02 2008 +0200
5  files:       Makefile
6  description:
7  Get make to generate the final binary from a .o file.
8  
9  

たい-p ないし--patchオプションしてくださいこのオプションにより unified diff これまでに unified diff たことがいのでしたら12.4  がありますされま

1   $ hg log -v -p -r 2
2  changeset:   2:fef857204a0c
3  user:        Bryan O’Sullivan <bos@serpentine.com>
4  date:        Sat Aug 16 22:05:04 2008 +0200
5  files:       hello.c
6  description:
7  Introduce a typo into hello.c.
8  
9  
10  diff -r 82e55d328c8c -r fef857204a0c hello.c
11  --- a/hello.c Fri Aug 26 01:21:28 2005 -0700
12  +++ b/hello.c Sat Aug 16 22:05:04 2008 +0200
13  @@ -11,6 +11,6 @@
14  
15   int main(int argc, char **argv)
16   {
17  - printf("hello, world!n");
18  + printf("hello, world!");
19    return 0;
20   }
21  

2.5 All about command options

Mercurial コマンドをここで中断してMercurial コマンドパタについてしましょうにおけるツア けるにつれてこのことをえておいてかったとうことでしょう

Mercurial コマンドしてオプションいにしてLinux および Unix システムオプショ したしたしています

ではロングネムオプションわりにショトネムオプション使しますこれはみというだけ のことですのでにするはありません

らかのコマンドくは -vないし--verboseオプションすることでよりくの-qない --quietオプションすることですることができます

2.6 Making and reviewing changes

このMercurial におけるできていますので実施そのってみましょう

まずめにすべきことはリポジトリからすることですリポジトリhg clone使 しましたがこのでのリポジトリからのありませんにあるリポジトリからすればいのです カルリポジトリネットワしのよりもですしくのにおいてディスクなくて ます4

1  $ cd ..
2  $ hg clone hello my-hello
3  updating working directory
4  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
5  $ cd my-hello

れますがしようとしたサンドボックスとしてのでもできますので リポジトリまっさらなつようにけるのがいでしょこうすることで うことができますしにそれらをするまではいのされたにすることができま カルリポジトリコストですからリポジトリおよびにはバヘッドどありませ

my-hello リポジトリには“hello, world” プログラムされたhello.c ファイルがありますではここでいにし えの sed コマンド使してするようにしてみましょう。(のためにsed 使するのはスクリプト よるであるからですければおそらくsed 使するいでしょうみのエディタ してください。)。

1  $ sed -i ’/printf/a∖∖tprintf("hello again!∖∖n");’ hello.c

hg statusコマンドによりリポジトリファイルする Mercurial されます

1  $ ls
2  Makefile  hello.c
3  $ hg status
4  M hello.c

つかのファイルしてはhg statusコマンドしませんがhello.c しては M しますしないされていないファイルしてhg statusしませ

MMercurial hello.c ファイルしていることをしますファイルってあるいは )、 Mercurial して通知するはありませんMercurial 実施することができま

hg statushello.c したことをるのにちますがどのようなったのかをりたいるでしょうるためにはhg diffコマンド使します

1  $ hg diff
2  diff -r 2278160e78d4 hello.c
3  --- a/hello.c Sat Aug 16 22:16:53 2008 +0200
4  +++ b/hello.c Mon Jul 20 21:59:02 2009 +0000
5  @@ -8,5 +8,6 @@
6   int main(int argc, char **argv)
7   {
8    printf("hello, world!");
9  + printf("hello again!n");
10    return 0;
11   }

2.7 Recording changes in a new changeset

してチェンジセットするにするまではファイルビルド するhg statusおよびhg diffによるするというしま

hg commitコマンドいることでチェンジセットたにすることができますこれを コミット実施“making a commit”ないし コミットする“committing”います

2.7.1 Setting up a username

hg commitにはずしも 5 すると りませんチェンジセットコミットMercurial コミットしたルアドレスチェンジセット しますのでもがからチェンジセットることができますMercurial 以下 しようとします

  1. hg commitコマンド-u オプションによってしたにその使され ます
  2. HGUSER 有無されます
  3. ムディレクトリusername.hgrc6 があるその使されますこのファイルくべきしては2.7.1してください
  4. EMAIL されているその使されます
  5. それMercurial しているシステムホストわせたルアドレス生成これを使しますこの方法生成されたにしてたないため Mercurial します

方法したMercurial によるコミットエラメッセしますそのようなでは しないコミットしないでしょう

HGUSER hg commitコマンドへの-u オプションMercurial ファイルusername にする してください使においてするには.hgrc ファイルするのがいで しょ方法するします

Creating a Mercurial configuration file

するにはまずはみのエディタ使ってムディレクトリ.hgrcファイルしますMercurial はこの ファイルから利用します.hgrc まずは以下のようになるでしょう

1  # This is a Mercurial configuration file.
2  [ui]
3  username = Firstname Lastname <email.address@domain.net>

[ui]ファイルセクションusername = ...というui セクションにおける username へのとみなされますセクションされたならたなセクションされるかファイルするま セクションきます#からまではMercurial によってコメントとみなされされま

Choosing a user name

username Mercurial えるではありますがリポジトリする利用のためのですの 使ですどの利用ルアドレスいたのようないていま

: Mercurial ウェブサではスパムメ利用ルアドレス収集してルアドレス難読すること ですこのいることでMercurial リポジトリウェブした することができます

2.7.2 Writing a commit message

チェンジセットでのするメッセするためにMercurial コミットエディタしますこの メッセコミットメッセえるためにされるものでコミットhg logコマ ンドによりされます

1  $ hg commit

hg commitコマンドするエディタHG:まるしていることでしょ

1  
2  HG: changed hello.c

Mercurial HG:まるしますこれらのチェンジセットへのとなるファイルコミット しようとしているらせるためだけのものですそのためこれらのちませ

2.7.3 Writing a good commit message

hg logコミットメッセしかしませんのでだけでじるにするのがいでしょう かられているためにコミットメッセ以下します

1  changeset:   73:584af0e231be
2  user:        Censored Person <censored.person@example.org>
3  date:        Tue Sep 26 21:37:07 2006 -0700
4  summary:     include buildmeister/commondefs.   Add an exports and install

コミットメッセしてはしませんコミットメッセしてプロジェクト としてらかのするかもしれませんがMercurial をすることはありませ

みはhg log --patchしただけではできないについてでありながらをもたら すようなコミットメッセです

2.7.4 Aborting a commit

コミットメッセコミットりやめをしたにはファイルせずにエディタ すればいのですこのリポジトリディレクトリのいずれにしてもえられませ

しでhg commitコマンドしたhg statusおよびhg diffによってされたての れます

2.7.5 Admiring our new handiwork

コミットしたならしがたしたチェンジセットhg tipコマンドすることができます コマンドhg logいますがされるのはリポジトリにおけるリビジョンだけで

1   $ hg tip -vp
2  changeset:   5:30682a1ee732
3  tag:         tip
4  user:        Bryan O’Sullivan <bos@serpentine.com>
5  date:        Mon Jul 20 21:59:02 2009 +0000
6  files:       hello.c
7  description:
8  Added an extra line of output
9  
10  
11  diff -r 2278160e78d4 -r 30682a1ee732 hello.c
12  --- a/hello.c Sat Aug 16 22:16:53 2008 +0200
13  +++ b/hello.c Mon Jul 20 21:59:02 2009 +0000
14  @@ -8,5 +8,6 @@
15   int main(int argc, char **argv)
16   {
17    printf("hello, world!");
18  + printf("hello again!n");
19    return 0;
20   }
21  

リポジトリにおけるリビジョンtip リビジョンあるいはtip びます

2.8 Sharing changes

Mercurial におけるリポジトリそれしている旨述べましたこれはたったしたチェン ジセットmy-hello リポジトリにしかしないことをしますこのリポジトリへとする方法 てゆきましょう

2.8.1 Pulling changes from another repository

まずめにhello リポジトリしてたったしたコミットされていないリポジトリしましょ このしたリポジトリhello-pull びます

1  $ cd ..
2  $ hg clone hello hello-pull
3  updating working directory
4  2 files updated, 0 files merged, 0 files removed, 0 files unresolved

hg pullコマンドによりmy-hello からhello-pull へとみますしかしながら闇雲リポジトリ むのはあまりぞっとしませんMercurial するhg incomingコマンドhg pullによってリポジトリまれるチェンジセットします

1  $ cd hello-pull
2  $ hg incoming ../my-hello
3  comparing with ../my-hello
4  searching for changes
5  changeset:   5:30682a1ee732
6  tag:         tip
7  user:        Bryan O’Sullivan <bos@serpentine.com>
8  date:        Mon Jul 20 21:59:02 2009 +0000
9  summary:     Added an extra line of output
10  

hg incomingコマンドしたリポジトリしてhg pullによるみの機会よりもよりくの することはですのでみはとはなるります。)

リポジトリへのみはどのリポジトリからむかを指示しつつhg pullコマンドするというなもの です

1  $ hg tip
2  changeset:   4:2278160e78d4
3  tag:         tip
4  user:        Bryan O’Sullivan <bos@serpentine.com>
5  date:        Sat Aug 16 22:16:53 2008 +0200
6  summary:     Trim comments.
7  
8  $ hg pull ../my-hello
9  pulling from ../my-hello
10  searching for changes
11  adding changesets
12  adding manifests
13  adding file changes
14  added 1 changesets with 1 changes to 1 files
15  (run ’hg update’ to get a working copy)
16  $ hg tip
17  changeset:   5:30682a1ee732
18  tag:         tip
19  user:        Bryan O’Sullivan <bos@serpentine.com>
20  date:        Mon Jul 20 21:59:02 2009 +0000
21  summary:     Added an extra line of output
22  

実施hg tipかられるようにリポジトリへのしていますんだ ディレクトリにおいてするためにはもうひとです

2.8.2 Updating the working directory

リポジトリディレクトリについてこれまではにしかしてきませんでした2.8.1  したhg pullコマンドリポジトリへのみをいますがしてみればわかるようににはぼしませ これはhg pullぼさないものであるためですにはhg pull はなくhg updateいます

1  $ grep printf hello.c
2   printf("hello, world!");
3  $ hg update tip
4  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
5  $ grep printf hello.c
6   printf("hello, world!");
7   printf("hello again!n");

hg pullしないことはえるかもしれませんがはそれにはりまhg updateいることでリポジトリされたへとディレクトリすることができますディレクトリえばバグ調などのために にしてしていたなどhg pullディレクトリしてしまうのはあまりよろしくないでしょ

しかしhg pull hg updateというれはですからhg pull-u オプションすることで Mercurial はこれらつをわせたします

1  hg pull -u

2.8.1  での-u オプションしないhg pullにはディレクトリであるこ とを喚起メッセされているのがれます

1  (run ’hg update’ to get a working copy)

ディレクトリがどのづいているかをるにはhg parentsコマンド使します

1  $ hg parents
2  changeset:   5:30682a1ee732
3  tag:         tip
4  user:        Bryan O’Sullivan <bos@serpentine.com>
5  date:        Mon Jul 20 21:59:02 2009 +0000
6  summary:     Added an extra line of output
7  

 2.4 ではチェンジセットかれています根元にあたるチェンジセットそしてにあ たるチェンジセットしていますじようにディレクトリっておりしているディレ クトリそのチェンジセットづいたものです

ディレクトリのものにするhg updateコマンドリビジョンないしチェンジセット ID します

1  $ hg update 2
2  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
3  $ hg parents
4  changeset:   2:fef857204a0c
5  user:        Bryan O’Sullivan <bos@serpentine.com>
6  date:        Sat Aug 16 22:05:04 2008 +0200
7  summary:     Introduce a typo into hello.c.
8  
9  $ hg update
10  2 files updated, 0 files merged, 0 files removed, 0 files unresolved

をしなかったにおけるhg updateれるようにhg updatetip されたものとしています

2.8.3 Pushing changes to another repository

Mercurial では現在作っているリポジトリからリポジトリへのですしたhg pull まずはとするためのリポジトリします

1  $ cd ..
2  $ hg clone hello hello-push
3  updating working directory
4  2 files updated, 0 files merged, 0 files removed, 0 files unresolved

hg outgoingコマンドリポジトリへのとなるチェンジセットします

1  $ cd my-hello
2  $ hg outgoing ../hello-push
3  comparing with ../hello-push
4  searching for changes
5  changeset:   5:30682a1ee732
6  tag:         tip
7  user:        Bryan O’Sullivan <bos@serpentine.com>
8  date:        Mon Jul 20 21:59:02 2009 +0000
9  summary:     Added an extra line of output
10  

そしてhg pushコマンドいます

1  $ hg push ../hello-push
2  pushing to ../hello-push
3  searching for changes
4  adding changesets
5  adding manifests
6  adding file changes
7  added 1 changesets with 1 changes to 1 files

hg pullhg pushコマンドリポジトリにおいてディレクトリいません hg pullhg pushリポジトリでのディレクトリする-u オプションちませ )。

リポジトリするチェンジセットっているみあるいはうとどうなるのでしょう ようなことはこりません

1  $ hg push ../hello-push
2  pushing to ../hello-push
3  searching for changes
4  no changes found

2.8.4 Sharing changes over a network

つかのれたコマンド利用にあるリポジトリにのみされているわけではありません ネットワ接続でもしますカルファイルシステムパスわりにURL すればいので

1  $ hg outgoing http://hg.serpentine.com/tutorial/hello
2  comparing with http://hg.serpentine.com/tutorial/hello
3  searching for changes
4  changeset:   5:30682a1ee732
5  tag:         tip
6  user:        Bryan O’Sullivan <bos@serpentine.com>
7  date:        Mon Jul 20 21:59:02 2009 +0000
8  summary:     Added an extra line of output
9  

このではリポジトリして映可ることができますがこのリポジトリでのすよ うにはですがされていません

1  $ hg push http://hg.serpentine.com/tutorial/hello
2  pushing to http://hg.serpentine.com/tutorial/hello
3  searching for changes
4  ssl required