Install specific git version on MacOS using brew

Viewed 2030

I am trying to install an older git version from brew.

I have installed git 2.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)

I want (for some troubleshooting purposes) an older version, namely 2.25.1

Why does it seem like there are no other (older) versions available?

▶ 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.

I have also tried the suggestions of this older SO topic with no luck whatsoever.

1 Answers

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

The supported method of installing specific versions of some formulae is to see if there is a versioned formula (e.g. gcc@7) available. If the version you’re looking for isn’t available, consider using brew extract.

Run these commands to create a tap named $USER/local-tap, extract git 2.25.1 into your tap, and install:

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
Related