$ sudo apt install mercurial
$ sudo -H pip3 install mercurial
libbz2-dev と libffi-dev が必要。[ui] username = ユーザ名 <メールアドレス>
| 項目 | 設定名 | 設定値 |
|---|---|---|
| ui | username | ユーザ名 <メールアドレス> |
| merge | マージする際に差分を表示する外部ツール (diff3 あたりを書いておけば良さそう) | |
| ignore | すべてのリポジトリに共通な無視リストのファイルパス | |
| alias | エイリアス名 | mercurialのコマンド (例: ci = commit) |
| extentions | エクステンション名 | なし(詳しくは エクステンションに記述) |
基本的には git と同じ
以降は、2を必要に応じて行いつつ、3を繰り返す
$ hg init
$ hg add [ファイル]
$ hg revert [取り消したいファイル]
$ hg status
status は st でも可glob: ワイルドカードre あるいは regexp: Perl や Python の正規表現syntax: regexp \/?\.\~lock\..+ \/?\~\$.+ \.zip$
$ hg forget <ファイル>
$ hg rm <ファイル>
rm は remove でも可$ hg cp <コピー元> <コピー先>
cp は copy でも可$ hg mv <ファイル> <変更後の名前>
mv は rename でも可$ hg commit
$ hg commit -m <コミットメッセージ>
$ hg commit -l <コミットメッセージファイル
$ hg commit <コミットしたいファイル>
$ hg rollback
add したものは remove や forget するまで常にトラッキングされる。hg commit FILE としてファイルを指定する。rollback 以外では以下の通りである (事前に MQ エクステンションを有効にしておく必要あり)。$ hg qimport -r REV_ID $ hg qrefresh FILE $ hg qfinish -a
REV_ID: 修正したいリビジョン番号FILE: 本来コミットするはずだったファイル群qimport -r の後に、hg qseries -s や hg qdiff などで誤ったリビジョンの確認をすると確実。$ hg log [オプション]
-r: リビジョンを指定-l: リビジョンの表示数 (指定がない場合は、すべて表示する)-v: コミットメッセージ全文を表示するchangeset: 1:96a83a913743 <- 2回目のコミットの「リビジョン番号:ハッシュ」 tag: tip <- タグ user: hoge <hoge@example.com> <- コミットしたユーザ date: Wed May 18 10:16:22 2016 +0900 <- コミット日時 summary: 2nd commit <- コミットメッセージのタイトル(1行目の内容) changeset: 0:0ed873115825 <- 1回目のコミットの「リビジョン番号:ハッシュ」 user: hoge <hoge@example.com> <- コミットしたユーザ date: Wed May 18 10:15:11 2016 +0900 <- コミット日時 summary: 1st commit <- コミットメッセージのタイトル(1行目の内容)
$ hg update [オプション] <リビジョン>
-C をつけると作業領域の変更を破棄するupdate は checkout でも可$ hg revert [オプション] <ファイル>
-r <リビジョン>: 特定のリビジョンのコミット状態に戻す (このオプションを付けない場合、直前のリビジョンに戻す)$ hg cat -r <リビジョン> -o <別名> <ファイル>
$ hg strip <リビジョン>
$ hg unbundle .hg/strip-backup/<ハッシュ>.hg
$ hg branch <ブランチ名>
$ hg branch
$ hg branches
$ hg checkout <ブランチ名>
$ hg merge <マージしたいブランチ>
$ hg strip <削除したいブランチ>
[extensions] 以下に追記rebase =
$ hg update <リビジョンの移動先ブランチ> $ hg rebase --source revision_s --dest revision_d --keep
revision_s: 移動させたいリビジョンの開始番号 (指定した番号以降のリビジョンも一緒に移動する)revision_d: 移動先のリビジョン番号 (指定されたリビジョンの後に、移動指定したリビジョンが取り付けられる)–keep: デフォルトでは、リビジョン移動後に移動元のブランチが消されるため、このオプションを付けて消さないようにする$ hg archive [オプション] -r <リビジョン> <出力名>
-X 除外ファイル: 除外ファイルを指定する-X .hg* (.hg や .hgignore を除外する)@ changeset: 3:c56f122d5366 | tag: tip | user: mumeiyamibito | date: Fri Oct 28 09:52:22 2016 +0900 | summary: 4th commit | o changeset: 2:315becd9db3f | user: mumeiyamibito | date: Fri Oct 28 09:52:12 2016 +0900 | summary: 3rd commit | o changeset: 1:88774b2a3443 | user: mumeiyamibito | date: Fri Oct 28 09:52:06 2016 +0900 | summary: 2nd commit | o changeset: 0:93daa7d382ae user: mumeiyamibito date: Fri Oct 28 09:52:00 2016 +0900 summary: 1st commit
$ hg histedit <リビジョン>
$ hg histedit 1
pick <リビジョンのハッシュ> <リビジョン番号> <コミットメッセージ> のリストが表示されるpick 88774b2a3443 1 2nd commit pick 315becd9db3f 2 3rd commit pick c56f122d5366 3 4th commit # Edit history between 88774b2a3443 and c56f122d5366 # # Commits are listed from least to most recent # # Commands: # # e, edit = use commit, but stop for amending # m, mess = edit commit message without changing commit content # p, pick = use commit # d, drop = remove commit from history # f, fold = use commit, but combine it with the one above # r, roll = like fold, but discard this commit's description #
pick を edit あるいは e に変更するedit 88774b2a3443 1 2nd commit
edit 315becd9db3f 2 3rd commit
pick c56f122d5366 3 4th commit
# Edit history between 88774b2a3443 and c56f122d5366
#
# Commits are listed from least to most recent
#
# Commands:
#
# e, edit = use commit, but stop for amending
# m, mess = edit commit message without changing commit content
# p, pick = use commit
# d, drop = remove commit from history
# f, fold = use commit, but combine it with the one above
# r, roll = like fold, but discard this commit's description
#
$ hg histedit --continue
$ hg histedit --continue
$ hg pull -f /path/to/repository $ hg merge $ hg commit
/path/to/repository: 統合したい別のリポジトリのパスpull を使っているが、ローカルのリポジトリでも問題ない$ hg convert /path/to/original_repository /path/to/new_repository --filemap map.txt
/path/to/original_repository: コピー元のリポジトリのパス/path/to/new_repository: 新たに作成する特定ファイルのみの別リポジトリのパスmap.txt: フィルタ条件を書き込んだファイルinclude INCLUDE_FILE_PATH exclude EXCLUDE_FILE_PATH rename ORIGINAL_PATH RENAMED_PATH
INCLUDE_FILE_PATH: リポジトリコピーの際に、コピーするファイルのパス (リポジトリのトップパスがベース)EXCLUDE_FILE_PATH: リポジトリコピーの際に、外したいファイルのパス (リポジトリのトップパスがベース)ORIGINAL_PATH: リポジトリコピーの際に、名前を変更したいファイルのパス (リポジトリのトップパスがベース)RENAMED_PATH: リポジトリコピーの際に、名前変更後のパス (リポジトリのトップパスがベース)include も exclude も指定していない場合、すべてのファイルがコピーされる。rename は事前に include しておく必要あり (rename だけではコピーされない)include や exclude の後に、ファイルのパスを続けて指定するとエラーが出る。)class/class1.py と class/class2.py のみのリポジトリを作成する (class1.py はリポジトリのトップに class_main.py として配置する)include class/class1.py include class/class2.py rename class/class1.py class_main.py
.hgrc の [extensions] 以下に追記する。[extensions] convert=
abort: data/FILE.i@XXXXXXXXXXXX: no match found! というエラーが現れることがある (FILE はその名前のファイルのトラッキングデータ)。$ hg convert --config convert.hg.ignoreerrors=True SOURCE_REPO DEST_REPO
SOURCE_REPO: 修復したいリポジトリ (mercurial で管理しているディレクトリ)DEST_REPO: 修復後のリポジトリの出力先~/.hgrc の [ui] に SSH の設定を追記することで利用できる。[ui] ssh = ssh -i PRIVATE_KEY -p PORT
PRIVATE_KEY: 秘密鍵のパスPORT: ポート番号$ hg clone . ssh://USER_NAME@SERVER_NAME/path/to/new_repository
USER_NAME: SSH のユーザ名SERVER_NAME: SSH のサーバ名 (IP アドレス)path/to/new_repository: サーバ内のパス (USER_NAME が指定されているのであれば、/home/USER_NAME が起点になる)$ hg push ssh://USER_NAME@SERVER_NAME/path/to/repository
USER_NAME: SSH のユーザ名SERVER_NAME: SSH のサーバ名 (IP アドレス)path/to/repository: サーバ内のパス (USER_NAME が指定されているのであれば、/home/USER_NAME が起点になる)$ hg clone ssh://USER_NAME@SERVER_NAME/path/to/repository
USER_NAME: SSH のユーザ名SERVER_NAME: SSH のサーバ名 (IP アドレス)path/to/repository: サーバ内のパス (USER_NAME が指定されているのであれば、/home/USER_NAME が起点になる)$ hg pull ssh://USER_NAME@SERVER_NAME/path/to/repository
USER_NAME: SSH のユーザ名SERVER_NAME: SSH のサーバ名 (IP アドレス)path/to/repository: サーバ内のパス (USER_NAME が指定されているのであれば、/home/USER_NAME が起点になる)$ hg root
[extentions] エクステンション名 = エクステンション名 = エクステンションのパス
hg log と同様の感覚で、hg glog。$ hg convert <GITリポジトリ> <新リポジトリ>
[color] に mode = auto[progress] に deley = 1.5histedit = /path/to/histedit/hg_histedit.pyと記述する方法が書かれているが、Ver. 2.3 以降はデフォルトでインストールされている (ちなみに Ubuntu 16.04 相当では、Ver. 3.7.3 なので mercurial インストールするだけでこのエクステンションはインストールされている)histedit = を .hgrc の [extensions] 以下に記述するだけで良いzipdoc = /path/to/zipdoc.py を追記する (/path/to/zipdoc.py は zipdoc.py のパスを入力)$ git clone http://repo.or.cz/r/fast-export.git fast-export
NEW_GIT_REPO を作成する。$ mkdir NEW_GIT_REPO $ cd NEW_GIT_REPO $ git init
$ ../fast-export/hg-fast-export.sh -r HG_REPO_PATH
HG_REPO_PATH: 変換したい mercurial のリポジトリパスhg status や hg log などの結果はデフォルトでは、less コマンド (pager) のように表示される。$HOME/.hgrc に以下を追記すると良い。[pager] ignore = SUBCOMMAND [, SUBCOMMND, ...]
SUBCOMMAND: pager を無効化したいサブコマンド (log や status など hg の後に付けるキーワード)–pager false を各コマンドの後ろにでも付けておけば良い。$ hg log --pager false