在MacOS上使用brew安装特定的git版本



我正在尝试从brew安装较旧的git版本。

I have installedgit2.33.1

▶ brew info git
git: stable 2.33.0 (bottled), HEAD
Distributed revision control system
https://git-scm.com
/usr/local/Cellar/git/2.33.0_1 (1,508 files, 42MB) *
Poured from bottle on 2021-10-08 at 12:06:00
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git.rb
License: GPL-2.0-only
==> Dependencies
Required: gettext ✔, pcre2 ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.
zsh completions and functions have been installed to:
/usr/local/share/zsh/site-functions
Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/git
==> Analytics
install: 198,758 (30 days), 658,960 (90 days), 2,607,801 (365 days)
install-on-request: 194,065 (30 days), 644,952 (90 days), 2,558,858 (365 days)
build-error: 0 (30 days)

我想要(出于一些故障排除的目的)一个旧版本,即2.25.1

为什么似乎没有其他(旧的)版本可用?

▶ brew install git@2.25.1
Warning: No available formula or cask with the name "git@2.25.1".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

我也试过这个老SO话题的建议,但没有任何运气。

https://docs.brew.sh/Tips-N'-Tricks#installing-previous-versions-of-formulae

的支持方法安装特定版本的一些公式是否有版本公式(例如gcc@7)可用。如果您正在寻找的版本不可用,请考虑使用brew extract

运行以下命令创建一个名为$USER/local-tap的tap,将git2.25.1解压到tap中,并安装:

brew tap-new --no-git $USER/local-tap
brew extract --version=2.25.1 git $USER/local-tap
brew install git@2.25.1
/usr/local/opt/git@2.25.1/bin/git --version