How to remove the shallow clone warning from HomeBrew

➜  ~ brew info test
Error: No available formula with the name "test"
==> Searching for a previously deleted formula...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow


Error: No previously deleted formula found.

I have modified the git remote address to mirror address of homebrew before. Maybe it's relevant to this but I don't know.

124539 次浏览

Under the cover Homebrew uses Git for version control, and a shallow clone is one that doesn't contain all history revisions/commits, for efficiency and data volume.

Actually, in most cases the warning can be safely ignored, as the formulae being searched for probably isn't available.

But if you're really looking for some formulae which might existed in the past, Just do what it suggests:

To get complete history run:

git -C "$(brew --repo homebrew/core)" fetch --unshallow

This way Homebrew could search for formula that existed only in the past but removed at some point.

I would advise against unshallowing the clone because it cramps disk space, makes the lookups slower and enables you only to install obsolete or unmaintaned applications.

There is currently no way to silence this warning. It was proposed in this Github issue but then ignored.

The function deleted_reason which prints the message contains a silent argument but afaik there is no way to use to use something like silent from the CLI commands which later call deleted_reason.

As of Oct 2020 Homebrew no longer creates shallow clones when being installed, and as of Dec 2020 updating existing shallow clones is not allowed either.

(This makes the original question about silencing the warning moot).


If a shallow clone is configured, a message containing text like the below will be shown:

Error:
homebrew-core is a shallow clone.
homebrew-cask is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow

It is now required to perform the unshallow process by running the git command(s) in the error message.

Note: This process may take a long time to complete without providing feedback.


For some details about the motivation for this change, see this discussion on Homebrew's GitHub page, specifically:

There are two major downsides of shallow cloning:

  1. It places a massive computation burden on GitHub's servers, which have to dynamically compute a fresh delta between what you have and the latest commit, on every brew update. (With full clones, GitHub can simply send you all the commits that happened after your last pull, and your local Git client takes care of the rest.)
  2. Because of [1], it makes it far more likely that GitHub will rate-limit Homebrew operations, which will make it suck for everyone.

--gromgit Dec 5, 2020, 12:29 AM EST

And also this additional text added to the error message:

This restriction has been made on GitHub's request because updating shallow clones is an extremely expensive operation due to the tree layout and traffic of Homebrew/homebrew-core and Homebrew/homebrew-cask.

git -C "$(brew --repo homebrew/core)" fetch --unshallow

This command should run with sudo and it would work.

sudo git -C "$(brew --repo homebrew/core)" fetch --unshallow

Terminal Picture

Fetch the repo using the --unshallow flag:

git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

I have update repo through git pull --unshallow

Update homebrew-core

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git pull --unshallow

Update homebrew-cask

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
git pull --unshallow

somehow the unshallow is not working for me, I wait like 10 mins but nothing show up, even with -v option.

Just found one possible solution that might working(at least working for me).

You can remove the repository and clone again to get latest one.

cd /usr/local/Homebrew/Library/Taps/homebrew/
rm -rf homebrew-core
git clone https://github.com/Homebrew/homebrew-core.git

same command for homebrew-cask if you need to update that too

all the credits belong to this answer

i dont know if this is the right way but does work git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

wait some minutes. After that you'll see something like this.

Resolving deltas: 100% (723461/723461), completed with 4329 local objects. From https://github.com/Homebrew/homebrew-core 4d2aadabe6c..eab34538365 master -> origin/master

then you could paste this again to update Homebrew and that's it.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

i'm new coding so i don't have a exact explenation to this.

At the time of writing this, the logic Homebrew uses for checking if your clone is shallow is by checking if either of /usr/local/Homebrew/Library/Taps/homebrew/homebrew-{cask,core}/.git/shallow exists.

One can work around that check by moving the .git directory out of the repo; example command to do so (run in the Terminal):

for tap in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-{cask,core}; do \
mv $tap{/,}.git ; \
echo "gitdir: $tap.git" >$tap/.git ; \
done

Reference: Setting up .git folder in a custom location

Homebrew foundation is unfortunately incredibly hostile towards their community and I wouldn't be surprised if they patched this soon.

Nonetheless, this is a lifesaver for me and possibly other people in similar situation to mine. However, if your life doesn't immediately depend on this, perhaps do them a favor and just unshallow.