Skip to content

Instantly share code, notes, and snippets.

@marcizhu
Last active October 31, 2020 01:21
Show Gist options
  • Save marcizhu/43cbc9045ff1ce3ef8329185a1ef4f49 to your computer and use it in GitHub Desktop.
Save marcizhu/43cbc9045ff1ce3ef8329185a1ef4f49 to your computer and use it in GitHub Desktop.
[Downgrade any Homebrew package easily] #brew #macos

Downgrade any Homebrew package easily

This guide will use the package git-delta for illustrative purposes only. Replace that with any package you want to downgrade.

Step 0: Uninstall current version (if installed):

$ brew uninstall git-delta

Step 1: Run brew info git-delta to find the formula link:

$ brew info git-delta
...
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git-delta.rb
License: MIT
...

Step 2: Open the formula link in your web browser.

Step 3: Run brew log git-delta. Since homebrew uses git version control system, all changes to its formulae are stored in commits. You need to choose the id (aka hash) of the commit that you want to downgrade to. The newest commits will be at the top. I picked a commit with the id f21eb378c8855cf9332e1f305f6b6dbeaeadf000 to get version 0.1.1.

Step 4: In your browser, replace the commit tag (usually HEAD/master) with your commit. In my case, it looks like this: https://github.com/Homebrew/homebrew-core/blob/f21eb378c8855cf9332e1f305f6b6dbeaeadf000/Formula/git-delta.rb. After that, press enter to load that version of the file.

Step 5: Right click on the "Raw" button, and press "Save as...". Save it with any name ended in .rb. In my case, I chose git-delta.rb.

Step 6: From your terminal, navigate to the folder where your downloaded file is, and use it to install the package. Replace git-delta.rb with your file name:

$ brew install git-delta.rb

Step 7: Pin your package so it doesn't get automatically updated to the latest version:

$ brew pin git-delta

Step 8: Delete your Ruby formula (if desired) and enjoy! Running brew info git-delta should show that you have installed the correct version and that it is pinned at the desired version:

$ brew info git-delta
git-delta: stable 0.4.3 (bottled), HEAD [pinned at 0.1.1]
Syntax-highlighting pager for git and diff output
https://github.com/dandavison/delta
Conflicts with:
  delta (because both install a `delta` binary)
/usr/local/Cellar/git-delta/0.1.1 (7 files, 3.5MB) *
  Built from source on 2020-10-10 at 23:42:25
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git-delta.rb
License: MIT
==> Dependencies
Build: rust ✘
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 1,336 (30 days), 6,835 (90 days), 13,689 (365 days)
install-on-request: 1,333 (30 days), 6,822 (90 days), 13,677 (365 days)
build-error: 0 (30 days)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment