[macOS General] Meld: Diff & Merge tool fot Git
こちらで紹介されていた Meld が気になったので、インストールしてみました。
が、いろいろ未決な memo.
[markdown]
> * [version control – What’s the best visual merge tool for Git? – Stack Overflow](http://stackoverflow.com/questions/137102/whats-the-best-visual-merge-tool-for-git)
> * [Meld](http://meldmerge.org/)
## インストール
Python も入れた方が良いようなので、あわせてインストールします。
* XQuartz
* Python
### XQuartz のインストール
> * [X11 および OS X について](http://support.apple.com/kb/HT5293?viewlocale=ja_JP)
`brew cask` でインストールします。
> * [brew bundle / cask で Homebrew も他の Mac アプリもまとめて管理・インストールする | deadwood](https://www.d-wood.com/blog/2014/03/12_5808.html)
“`prettyprinted
% brew cask info XQuartz
xquartz: 2.7.5
http://xquartz.macosforge.org/
Not installed
https://github.com/phinze/homebrew-cask/commits/master/Casks/xquartz.rb
==> Contents
XQuartz.pkg (install)
% brew cask install xquartz
==> Downloading http://xquartz.macosforge.org/downloads/SL/XQuartz-2.7.5.dmg
######################################################################## 100.0%
==> Running installer for xquartz; your password may be necessary.
Password:
==> installer: Package name is XQuartz 2.7.5
==> installer: Installing at base path /
==> installer: The install was successful.
==> Sorry, try again.
xquartz installed to ‘/opt/homebrew-cask/Caskroom/xquartz/2.7.5’ (64M)
“`
Mac を一度再起動します。
#### はまりポイント
以下、エラーログ。
* Mac の再起動が必要でした。
> * [Getting Meld working on Mac OSX 10.9 | Kenny Holden](http://www.codez.co.uk/2014/02/meld-on-mac-osx-mavericks-10-9/)
* XQuartz (X11) がない環境では、meld のインストール時に以下のエラーが表示されました。
“`prettyprinted
% brew instal meld
pygtk: Unsatisfied dependency: XQuartz
Homebrew does not package XQuartz. Installers may be found at:
https://xquartz.macosforge.org
gtksourceview: Unsatisfied dependency: XQuartz
Homebrew does not package XQuartz. Installers may be found at:
https://xquartz.macosforge.org
pango: Unsatisfied dependency: XQuartz
Homebrew does not package XQuartz. Installers may be found at:
https://xquartz.macosforge.org
gtk+: Unsatisfied dependency: XQuartz 2.3.6
Homebrew does not package XQuartz. Installers may be found at:
https://xquartz.macosforge.org
py2cairo: Unsatisfied dependency: XQuartz
Homebrew does not package XQuartz. Installers may be found at:
https://xquartz.macosforge.org
meld: Unsatisfied dependency: XQuartz
Homebrew does not package XQuartz. Installers may be found at:
https://xquartz.macosforge.org
cairo: Unsatisfied dependency: XQuartz
Homebrew does not package XQuartz. Installers may be found at:
https://xquartz.macosforge.org
Error: Unsatisifed requirements failed this build.
“`
* GtkWarning は、XQuartz インストール後、Mac 再起動すればOK。
“`prettyprinted
% meld
Couldn’t bind the translation domain. Some translations won’t work.
‘module’ object has no attribute ‘bindtextdomain’
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
warnings.warn(str(e), _gtk.Warning)
/usr/local/Cellar/meld/1.8.4/libexec/bin/meld:155: GtkWarning: gtk_icon_theme_get_for_screen: assertion ‘GDK_IS_SCREEN (screen)’ failed
gtk.icon_theme_get_default().append_search_path(meld.paths.icon_dir())
Traceback (most recent call last):
File “/usr/local/Cellar/meld/1.8.4/libexec/bin/meld”, line 155, in
gtk.icon_theme_get_default().append_search_path(meld.paths.icon_dir())
AttributeError: ‘NoneType’ object has no attribute ‘append_search_path’
“`
### Python のインストール
Python を先にインストールします。
“`prettyprinted
% brew install python
% brew info python
python: stable 2.7.6 (bottled), HEAD
http://www.python.org
/usr/local/Cellar/python/2.7.6 (4632 files, 74M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/python.rb
==> Dependencies
Build: pkg-config ✔
Required: openssl ✔
Recommended: readline ✔, sqlite ✔, gdbm ✔
==> Options
–quicktest
Run `make quicktest` after the build (for devs; may fail)
–universal
Build a universal binary
–with-brewed-tk
Use Homebrew’s Tk (has optional Cocoa and threads support)
–with-dtrace
Experimental DTrace support (http://bugs.python.org/issue13405)
–with-poll
Enable select.poll, which is not fully implemented on OS X (http://bugs.python.org/issue5154)
–without-gdbm
Build without gdbm support
–without-readline
Build without readline support
–without-sqlite
Build without sqlite support
–HEAD
install HEAD version
==> Caveats
Setuptools and Pip have been installed. To update them
pip install –upgrade setuptools
pip install –upgrade pip
You can install Python packages with
pip install
/usr/local/lib/python2.7/site-packages
See: https://github.com/Homebrew/homebrew/wiki/Homebrew-and-Python
.app bundles were installed.
Run `brew linkapps` to symlink these to /Applications.
“`
ターミナルを再起動する。
“`prettyprinted
% which python
/usr/local/bin/python
% python –version
Python 2.7.6
“`
#### はまりポイント
* ターミナルを再起動する必要がありました。
* インストールの順番を間違えるとうまくいかないこともあるらしい。
“`prettyprinted
% brew deps meld | grep py
py2cairo
pygobject
pygtk
pygtksourceview
python
% brew uninstall py2cairo
Uninstalling /usr/local/Cellar/py2cairo/1.10.0…
% brew uninstall pygobject
Uninstalling /usr/local/Cellar/pygobject/2.28.6…
% brew uninstall pygtk
Uninstalling /usr/local/Cellar/pygtk/2.24.0…
% brew uninstall pygtksourceview
Uninstalling /usr/local/Cellar/pygtksourceview/2.10.0…
% brew uninstall python
Uninstalling /usr/local/Cellar/python/2.7.6…
% brew uninstall meld
Uninstalling /usr/local/Cellar/meld/1.8.4…
“`
> * [Unable to run meld · Issue #24486 · Homebrew/homebrew](https://github.com/Homebrew/homebrew/issues/24486)
> * [Installing Meld with Brew](http://www.thefarsideoffailure.com/blog/brew_installed_meld)
### Meld のインストール
“`prettyprinted
% brew info meld
meld: stable 1.8.4
http://meldmerge.org
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/meld.rb
==> Dependencies
Build: xz ✔, intltool ✔, rarian ✔
Required: pygtk ✘, pygtksourceview ✘, pygobject ✘
“`
以下で X11 アプリとして起動するようになった。
“`prettyprinted
% meld
Couldn’t bind the translation domain. Some translations won’t work.
‘module’ object has no attribute ‘bindtextdomain’
/usr/local/lib/python2.7/site-packages/gobject/__init__.py:115: Warning: Attempt to add property HistoryCombo::history-id after class was initialised
type_register(cls, namespace.get(‘__gtype_name__’))
“`
いろいろ warn がでているが、直し方がわからない。
どうも OS X Mavericks にしてから、python 依存のアプリで warn がでるような気がする。
## つかいかた
こちらを使わせていただき、テストを行う。
> * [eiel/git-merge-sandbox · GitHub](https://github.com/eiel/git-merge-sandbox)
“`prettyprinted
% git clone https://github.com/eiel/git-merge-sandbox.git
Cloning into ‘git-merge-sandbox’…
remote: Counting objects: 23, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 23 (delta 5), reused 21 (delta 4)
Unpacking objects: 100% (23/23), done.
Checking connectivity… done.
% cd git-merge-sandbox
% bin/restart
HEAD is now at 79c8638 add master
Auto-merging sample2.txt
CONFLICT (add/add): Merge conflict in sample2.txt
Auto-merging sample.txt
CONFLICT (add/add): Merge conflict in sample.txt
Automatic merge failed; fix conflicts and then commit the result.
“`
“`prettyprinted
% git status
On branch master
Your branch is up-to-date with ‘origin/master’.
You have unmerged paths.
(fix conflicts and run “git commit”)
Unmerged paths:
(use “git add
both added: sample.txt
both added: sample2.txt
no changes added to commit (use “git add” and/or “git commit -a”)
“`
### Meld でファイルを開く
“`prettyprinted
% meld sample.txt
“`
ファイルのコンフリクトを直す。
### git mergetool から開く
Meld を Merge tool として利用するよう `~/.gitconfig` に設定を加える。
“`prettyprinted
% git config –global merge.tool “meld”
“`
設定後は以下を実行すると、一つずつコンフリクトしているファイルが開かれる。
“`prettyprinted
% git mergetool (git)-[master|merge]
Merging:
sample.txt
sample2.txt
Normal merge conflict for ‘sample.txt’:
{local}: created file
{remote}: created file
Hit return to start merge resolution tool (meld):
“`
修正完了後、次のファイルを以下のように開くか聞かれる。
“`prettyprinted
Normal merge conflict for ‘sample2.txt’:
{local}: created file
{remote}: created file
Hit return to start merge resolution tool (meld):
“`
### コンフリクト解消後
編集前のファイルは、`.orig` をつけて保存されるよう。
“`prettyprinted
% git status (git)-[master|merge]
On branch master
Your branch is up-to-date with ‘origin/master’.
All conflicts fixed but you are still merging.
(use “git commit” to conclude merge)
Untracked files:
(use “git add
sample.txt.orig
sample2.txt.orig
nothing added to commit but untracked files present (use “git add” to track)
% git commit (git)-[master|merge]
[master be28c39] Merge tag ‘feature’
% git status (git)-[master]
On branch master
Your branch is ahead of ‘origin/master’ by 2 commits.
(use “git push” to publish your local commits)
Untracked files:
(use “git add
sample.txt.orig
sample2.txt.orig
nothing added to commit but untracked files present (use “git add” to track)
“`
いろいろ悩んでみることにする。
## .gitconfig の設定
上記と重複する箇所もあるが、Meld を Diff & Merge tool として利用するための設定をまとめる。
### git mergetool
“`prettyprinted
% git config –global merge.tool “meld”
% git config –global mergetool.keepBackup false
“`
2行目の設定でバックアップファイルが作成されなくなる。
`git mergetool` で利用する。
### git difftool
こちらを参考に設定します。
> * [git – View differences of branches with meld? – Stack Overflow](http://stackoverflow.com/questions/2006032/view-differences-of-branches-with-meld#answer-12815806)
“`prettyprinted
% git config –global diff.guitool meld
“`
このように利用。
“`prettyprinted
% git difftool -g -d master
“`
* `-g` – `guidiff tool` つけなくても meld がつかわれました
* `-d` – `–dir-diff`
> * [git difftool –dir-diff が便利すぎて泣きそうです – てっく煮ブログ – Webデザイン・デザイナーの制作に役立つネタまとめ / ニコニコ風](http://feed.designlinkdatabase.net/feed/outsite_925121.aspx)
> * [Git – Git の設定](http://git-scm.com/book/ja/Git-%E3%81%AE%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA-Git-%E3%81%AE%E8%A8%AD%E5%AE%9A)
> * [Using meld with git diff » Deadlypenguin](http://blog.deadlypenguin.com/blog/2011/05/03/using-meld-with-git-diff/)
> * [wmanley/git-meld · GitHub](https://github.com/wmanley/git-meld)
> * [駄猫の備忘録: sourcetreeに外部diffツールを設定する](http://3a3k.blogspot.jp/2011/10/sourcetreediff.html)
## 補遺
> * [Mac で使える git mergetool をいろいろ試してみる – 準備編 – そんなこと覚えてない](http://blog.eiel.info/blog/2013/06/26/git-mergetool/)
> * [Gitを使った分散開発管理16 – p4mergeでマージを行う | Developers.IO](http://dev.classmethod.jp/tool/p4merge/)
> * [Mac OSX のDiffツール – Software Technology Memorandum and thoughts](http://makotow.github.io/blog/2013/02/08/mac-difftools/)
### 日本語の設定
> 日本語のファイルも認識させたい場合は、メニューから [編集] – [設定] – [エンコーディング] で `shift_jis euc-jp utf8 latin1` と入れる (この順番が大事)
>
> * [yukotan hour: MeldのMacへのインストール(Homebrew, Mountain Lion)](http://yukotan.blogspot.jp/2013/02/meldmachomebrew-mountain-lion.html)
### 環境変数 PYTHONPATH を設定
> * [OS X Lion で brew install した meld の実行時エラー | Drowsy Dog’s Diary](http://ka-zoo.net/2013/03/meld-on-os-x-lion/)
“`prettyprinted
% export PYTHONPATH=/usr/local/lib/python2.7/site-packages/
“`
[/markdown]