MacOS更新Git

说明

最近使用Mac电脑,发现Git不知道怎么升级,查了一下,特此记录

步骤

首先,在terminal执行

1
2
3
which git

/usr/bin/git

会显示

1
/usr/bin/git

再执行

1
git --version

会显示

1
git version 2.37.1 (Apple Git-137.1)

这个时候用的Xcode上的Git,再执行

1
brew install git
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
HOMEBREW_BREW_GIT_REMOTE set: using https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git as the Homebrew/brew Git remote.

remote: Enumerating objects: 326, done.

remote: Counting objects: 100% (326/326), done.

remote: Compressing objects: 100% (48/48), done.

remote: Total 631 (delta 305), reused 278 (delta 278), pack-reused 305

Receiving objects: 100% (631/631), 307.39 KiB | 17.08 MiB/s, done.

Resolving deltas: 100% (331/331), completed with 94 local objects.

From https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew

   10dd6a30c..8051e8818  master     -> origin/master

HOMEBREW_CORE_GIT_REMOTE set: using https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git as the Homebrew/homebrew-core Git remote.

Running `brew update --auto-update`...

remote: Enumerating objects: 1184, done.

remote: Counting objects: 100% (1184/1184), done.

remote: Compressing objects: 100% (98/98), done.

remote: Total 1673 (delta 1162), reused 1086 (delta 1086), pack-reused 489

Receiving objects: 100% (1673/1673), 1.10 MiB | 22.95 MiB/s, done.

Resolving deltas: 100% (1192/1192), completed with 223 local objects.

From https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core

   f8376785ae6..78c20992775  master     -> origin/master

==> Fetching dependencies for git: gettext and pcre2

==> Fetching gettext

==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/gettext-0.

######################################################################## 100.0%

==> Fetching pcre2

==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/pcre2-10.4

######################################################################## 100.0%

==> Fetching git

==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/git-2.39.2

######################################################################## 100.0%

==> Installing dependencies for git: gettext and pcre2

==> Installing git dependency: gettext

==> Pouring gettext-0.21.1.arm64_ventura.bottle.tar.gz

🍺  /opt/homebrew/Cellar/gettext/0.21.1: 1,983 files, 20.9MB

==> Installing git dependency: pcre2

==> Pouring pcre2-10.42.arm64_ventura.bottle.tar.gz

🍺  /opt/homebrew/Cellar/pcre2/10.42: 230 files, 6.2MB

==> Installing git

==> Pouring git-2.39.2.arm64_ventura.bottle.1.tar.gz

==> Caveats

The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.

Subversion interoperability (git-svn) is now in the `git-svn` formula.



zsh completions and functions have been installed to:

  /opt/homebrew/share/zsh/site-functions

==> Summary

🍺  /opt/homebrew/Cellar/git/2.39.2: 1,627 files, 48MB

==> Running `brew cleanup git`...

Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.

Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

==> Caveats

==> git

The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.

Subversion interoperability (git-svn) is now in the `git-svn` formula.



zsh completions and functions have been installed to:

  /opt/homebrew/share/zsh/site-functions

重新指定新Git地址

1
brew link git --overwrite

显示如下:

1
2
3
4
5
6
7
8
9
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api/formul

##O#-#                                                                        

Warning: Already linked: /opt/homebrew/Cellar/git/2.39.2

To relink, run:

  brew unlink git && brew link git

关闭terminal,重新查看git版本,执行

1
git --version

会显示如下:

1
git version 2.39.2

此时已经是当前最新版本了,再核查路径:

1
which git

显示如下:

1
/opt/homebrew/bin/git

显示路径与原来的Git安装路径一致。至此,Git版本升级完毕。

使用 Hugo 构建
主题 StackJimmy 设计