LoginSignup
23

More than 5 years have passed since last update.

GitHubをMercurialで使う

Posted at

Mercurialのhg-gitエクステンションを使うと、GitHub上のリポジトリをMercurialのリポジトリに変換して使うことができる。

準備

Mercurialのhg-gitエクステンションをインストール

hg clone https://bitbucket.org/durin42/hg-git
cd hg-git
sudo python setup.py install

~/.hgrc にプラグインを追加

[extensions]
hggit = /Library/Python/2.7/site-packages/hg_git-0.4.0-py2.7.egg/hggit

Mercurialのユーザー名とメールアドレスの関連づけ

hg-gitをデフォルトの状態で使うと、GitHubにはauthorのメールアドレスが none@none で送信されるため、GitHub上でauthorが invalid-email-address と表示されてしまう。

GitHubのユーザー名が正しく表示されるよう設定を行う。

[git]
authors = .hg/authors.txt
hg/authors.txt
somebody = foobar@example.com

※メールアドレスはGitHubのアカウントに登録されているものであること。

利用

GitHubリポジトリのclone

hg clone でgitリポジトリをcloneしてMercurialのリポジトリに変換できる。

なお、Mercurial 2.5.1とhg-git 0.4.0の環境では、空のgitリポジトリをcloneすることはできなかった。

# sshの場合
hg clone git+ssh://git@github.com:user/repository.git
# httpsの場合
hg clone git+https://github.com/user/repository.git

GitHubリポジトリへのpush

hg push

既存のMercurialリポジトリをGitHubにpush

リポジトリの .hg/hgrc でGitHubのリポジトリURLを設定してから hg push を実行する。

[paths]
default = git+ssh://git@github.com:user/repository.git

gitブランチの扱い

gitリポジトリのブランチはMercurialリポジトリではbookmarkに変換される。Mercurialリポジトリでbookmarkを作ってpushすると、gitリポジトリでブランチが作成される。

ローカルのgitリポジトリの所在

hg-gitでpull/pushを行っているMercurialリポジトリには、変換作業用のgitリポジトリ .hg/hgrc/git が存在する。

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23