Mercurialとは、
単に
一方Mercurialは、
「分散リポジトリ」
しかし、
この連載では、
Mercurialのインストール
本原稿執筆時点では、
OS | 形式 | 方法 |
---|---|---|
Linux/ |
Pythonスクリプト | パッケージ管理経由 |
ソースからビルド | ||
Windows | バイナリ(*.exe) | インストーラ経由 |
ソースからビルド | ||
Pythonスクリプト | Cygwinのsetup. |
|
ソースからビルド |
Linux/
Windows環境への導入は、
それぞれのインストール手順に関しては、
インストールが済んだなら、
まっさらな状態からリポジトリを作成する手順は次ページ以降で説明しますので、
% hg clone http://selenic.com/repo/hg mercurial-repo requesting all changes adding changesets adding manifests adding file changes added 6571 changesets with 12628 changes to 910 files 795 files updated, 0 files merged, 0 files removed, 0 files unresolved % ls -F mercurial-repo/ %
これで"mercurial-repo"ディレクトリ配下にMercurial自身のリポジトリが複製されました
例えば、
% cd mercurial-repo % hg log -l 10 changeset: 6570:626cb86a6523 tag: tip user: Benoit Allard <[email protected]> date: Thu Apr 24 17:16:02 2008 +0200 summary: add compression type type parameter to bundle command changeset: 6569:c15bfe9cdcd6 user: Benoit Allard <[email protected]> date: Thu Apr 24 11:48:07 2008 +0200 summary: add support for HG10GZ bundles to bundlerepo.bundlerevlog() : (省略) : %
"-l 10"オプションは、
もしもネットワーク接続を簡単に切断できる状況にあるなら、
一旦構成管理情報を取り込んでしまえば、
リポジトリの作成
プロジェクトの開始等で、
% hg init myrepo %
以上で"myrepo"ディレクトリ配下がMercurialの構成管理対象になりました
「リポジトリの作成」
Mercurialの

作成された
ちなみに、
% cd myproject % hg init % hg commit -A -m 'initial content' adding dir1/dir2/dir3/night.txt adding dir1/dir2/evening.txt adding dir1/morning.txt adding hello.txt .... %
"hg commit"に対する"-A"オプションは、
基本操作
Mercurialでは、
% echo "hello" > hello.txt % hg status ? hello.txt % hg diff % hg add hello.txt % hg status A hello.txt % hg diff diff -r 000000000000 hello.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hello.txt Mon May 05 21:15:32 2008 +0900 @@ -0,0 +1,1 @@ +hello % hg commit -m 'add hello.txt' % hg status % hg diff %
紙面
Mercurialのオンラインヘルプ機能は、
チェンジセット
MercurialはSubversionと同様に、
% hg log changeset: 0:a044b949325f tag: tip user: fujiwara date: Mon May 05 21:16:24 2008 +0900 summary: add hello.txt % hg log -v changeset: 0:a044b949325f tag: tip user: fujiwara date: Mon May 05 21:16:24 2008 +0900 files: hello.txt description: add hello.txt %
Mercurialはファイルのみを構成管理します
Mercurialで特定のチェンジセットを指す場合、
- リビジョン番号:"changeset:"値における(":")の左側
- 12桁ハッシュ値:"changeset:"値における(":")の右側
- 40桁ハッシュ値:"hg --debug log" 時のハッシュ値位置
先の"hg log"出力における最新のチェンジセットを指す場合、
ちなみに、
新しいツールやシステムを使い始める際に、
そこで、
ワーキングディレクトリへの操作の取り消し
"hg commit"により変更を確定する前の操作、
以下は、
% echo "good by" > goodby.txt % hg add goodby.txt % hg status -A A goodby.txt % hg revert goodby.txt % hg status -A ? goodby.txt %
以下は、
% hg remove hello.txt % ls hello.txt ls: cannot access hello.txt: No such file or directory % hg status -A R hello.txt % hg revert hello.txt % ls hello.txt hello.txt % hg status -A C hello.txt %
以下は、
% echo 'good by' >> hello.txt % hg status -A M hello.txt % hg diff diff -r a044b949325f hello.txt --- a/hello.txt Mon May 05 21:16:24 2008 +0900 +++ b/hello.txt Mon May 05 21:26:19 2008 +0900 @@ -1,1 +1,2 @@ hello hello +good by % hg revert hello.txt % hg status -A C hello.txt ? hello.txt.orig % hg diff %
以下は、
% rm hello.txt % hg status -A ! hello.txt % hg revert hello.txt % ls hello.txt hello.txt % hg status -A C hello.txt %
ご覧のように、
リポジトリへの操作の取り消し
間違って実行してしまった"hg commit"は、
「一回分しか取り消せない」
ことを
% echo "good by" >> goodby.txt % hg add goodby.txt % hg status A goodby.txt % hg commit -m 'goodby' % hg status % hg rollback rolling back last transaction % hg status A goodby.txt %
ファイルの複製・改名
Mercurialでは、
% hg copy hello.txt goodby_hg_copy.txt % hg commit -m 'copy hello to goodby' % hg log goodby_hg_copy.txt changeset: 1:b3fdaab39142 tag: tip user: fujiwara date: Mon May 05 21:30:58 2008 +0900 summary: copy hello to goodby % hg log -f goodby_hg_copy.txt changeset: 1:b3fdaab39142 tag: tip user: fujiwara date: Mon May 05 21:30:58 2008 +0900 summary: copy hello to goodby changeset: 0:a044b949325f user: fujiwara date: Mon May 05 21:16:24 2008 +0900 summary: add hello.txt %
"hg log"コマンドに"-f"
(1)
"hg revert"や"hg rollback"による取り消しと違い、
それでは
「分散リポジトリ」
複製方法あれこれ
一番簡単なリポジトリの複製方法は、
% ls -F myrepo/ % hg clone myrepo myrepo2 1 files updated, 0 files merged, 0 files removed, 0 files unresolved % ls -F myrepo/ myrepo2/ %
別な複製方法として、
% hg init myrepo3 % ls -F myrepo/ myrepo2/ myrepo3/ % cd myrepo3 % hg pull ../myrepo pulling from ../myrepo requesting all changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files (run 'hg update' to get a working copy) %
察しの良い方は
% hg init myrepo4 % ls -F myrepo/ myrepo2/ myrepo3/ myrepo4/ % cd myrepo % hg push ../myrepo4 pushing to ../myrepo4 searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files %
各リポジトリにおいて"hg log"出力を確認することで、
ちなみに、
「分散」≠「自動伝播」
リポジトリの複製ができたところで、
% cd myrepo % echo 'good morning' > morning.txt % hg add morning.txt % hg commit -m 'add morning' % hg log changeset: 1:b85af333a085 tag: tip user: fujiwara date: Mon May 05 21:57:35 2008 +0900 summary: add morning changeset: 0:a044b949325f user: fujiwara date: Mon May 05 21:16:24 2008 +0900 summary: add hello.txt %
"hg commit"によりmyrepoで変更を確定したなら、
"hg clone"、
「分散」
さて、

矩形内の数字は各リポジトリごとのリビジョン番号を、
この状況はまさに、
次回は、