[整理]Mac安裝Meld,並使用Meld作爲git diff tool的工具

在mac上安裝Meld,給Android Studio使用爲git diff的工具。
Ubuntu中Meld很好配置,mac中沒找到dmg包,在這篇博客中看到的下載的辦法:

Mac安裝Meld,並作爲git merge tool的工具

brew install Caskroom/cask/xquartz
brew install pygtk
brew cask install caskroom/cask/meld

安裝完了過後還有其他地方需要配置,一個是.gitconfig文件,
另外,遇到這樣的報錯

(meld:41258): Gtk-WARNING **: 09:23:58.646: Locale not supported by C library.
        Using the fallback 'C' locale.
Usage: 
  meld                              Start with an empty window
  meld <file|folder>                Start a version control comparison
  meld <file> <file> [<file>]       Start a 2- or 3-way file comparison
  meld <folder> <folder> [<folder>] Start a 2- or 3-way folder comparison

Error: too many arguments (wanted 0-3, got 7)

Couldn't set the locale: unsupported locale setting; falling back to 'C' locale

解決辦法:

參考這裏,git diff with meld

原文中

Meld is a diff tool, how to use it with git?
1.install meld:

sudo apt-get install meld

2.need a script:
2.1 in the teminal:

sudo gedit /bin/git-meld.sh

2.2 in the text plz input below:

#!/bin/sh
meld $2 $5

2.3 int the terminal:

sudo chmod +x /bin/git-meld.sh

3.set the git config in terminal:

git config --global diff.external /bin/git-meld.sh

我的改造

因爲我用的mac,bin/sh那個目錄裏新添加的文件不能write,沒法寫入內容。理解下上文的精髓,就是找個地方存一個文件,讓它成爲可執行文件,然後在裏邊把meld的默認行爲弄成meld $2 $5,從而解決

因爲meld只接受兩個參數,而git diff會傳遞7個參數,因此需要編寫個shell腳本轉換一下

這個問題。如上引用文字出處
確實能解決問題,不是大家瞎抄來抄去。

因爲我的meld最後是安裝在/usr/local/bin下,就把git-meld.sh文件也存在相同路徑下(其實可以寫文件就行,存哪裏都可以,只要在~/.gitconfig中配置好就行),.sh中寫的內容同上,就是meld $2 $5

katrinahuang@KatrinadeMacBook-Pro:/usr/local/bin$ vi git-meld.sh
katrinahuang@KatrinadeMacBook-Pro:/usr/local/bin$ sudo chmod +x /usr/local/bin/git-meld.sh
katrinahuang@KatrinadeMacBook-Pro:/usr/local/bin$ git config --global diff.external /usr/local/bin/git-meld.sh

好了,這是我的~/.gitconfig中[diff]部分的配置:

[diff]
 			tool = meld
 			external = /usr/local/bin/git-meld.sh

接着跑到開發工具的項目代碼路徑下去使用git diff,就是正常的比對的界面啦
截圖樣例
開心😺,靠自己也能夠解決一些工具相關的問題,一點點看見自己的能力。加油⛽️

發佈了69 篇原創文章 · 獲贊 39 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章