macOS 用 Homebrew 安裝 git 指令

本篇紀錄在 macOS 下用 Homebrew 安裝 git 指令與 git gui (gitk),macOS 內建沒有 git 指令所以需要自行安裝,
macOS 請先安裝 Homebrew,請參考官網教學安裝,macOS 有安裝過 Homebrew 也請更新,

1
brew update

Homebrew最新的版本為2.4.16

1
2
3
4
$ brew --version
Homebrew 2.4.16-39-g48c6dc8
Homebrew/homebrew-core (git revision 158ad0; last commit 2020-09-01)
Homebrew/homebrew-cask (git revision c1c3f; last commit 2020-09-01)

macOS 安裝 git 指令

接下來透過 Homebrew 安裝 git 指令

1
$ brew install git

如果之前已經透過 Homebrew 安裝 git 過,他應該會提示你用brew upgrade升級的指令,如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ brew install git
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/pcre2-10.35.high_sierra.bot
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/69c4fb400d19d1910df33
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/git-2.28.0.high_sierra.bott
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/5095b064dfafb8cf4cabd
######################################################################## 100.0%
Error: git 2.2.0 is already installed
To upgrade to 2.28.0, run `brew upgrade git`.
$ brew upgrade git
Updating Homebrew...
==> Upgrading 1 outdated package:
git 2.2.0 -> 2.28.0
==> Upgrading git 2.2.0 -> 2.28.0
==> Downloading https://homebrew.bintray.com/bottles/pcre2-10.35.high_sierra.bot
...

查看一下安裝 git 的版本,本次升級完 git 的版本為 2.28

1
2
$ git version
git version 2.28.0

which 指令檢查一下 git 指令是位在 /usr/local/bin/git
且軟連結到/usr/local/Cellar/git/2.28.0/bin/git

1
2
3
4
$ which git
/usr/local/bin/git
$ ls -al /usr/local/bin/git
lrwxr-xr-x 1 shengyu admin 28 9 1 22:35 /usr/local/bin/git -> ../Cellar/git/2.28.0/bin/git

macOS 安裝 gitk / git-gui

接下來透過 Homebrew 安裝 gitk 指令,安裝完後就可以使用 gitk 指令了

1
$ brew install git-gui

which 指令檢查一下 gitk 指令是位在 /usr/local/bin/gitk
且軟連結到/usr/local/Cellar/git-gui/2.28.0/bin/gitk

1
2
3
4
$ which gitk
/usr/local/bin/gitk
$ ls -al /usr/local/bin/gitk
lrwxr-xr-x 1 shengyu admin 33 9 1 22:37 /usr/local/bin/gitk -> ../Cellar/git-gui/2.28.0/bin/gitk

之前 git 2.2.0 時使用 gitk 明顯地畫質還沒跟上高解析度的螢幕,
經過這次的升級到 2.28.0 後,這 gitk 畫質不足問題已經獲得改善。