ChatGPT解决这个技术问题 Extra ChatGPT

Brew update failed: untracked working tree files would be overwritten by merge

Trying to update Homebrew with brew update I got the following error

error: The following untracked working tree files would be overwrittenby merge:     
 Library/Formula/argp-standalone.rb
 Library/Formula/cocot.rb 
Please move or remove them before you can merge. 
Aborting 
Updating e088818..5909e2c 
Error: Failed while executing git pull  origin refs/heads/master:refs/remotes/origin/master

I found a blog post by someone who experienced a similar problem after having installed Mountain Lion (which I did this week too). He explains how he removed the files referred to in the error message

I removed these files:
$ cd $(brew --prefix)
$ rm cocot.rb
However, removing these files didn't help with the brew update. Instead I had to manually update brew through git:
$ cd $(brew --prefix)
$ git fetch origin
$ git reset --hard origin/master
$ brew update
Already up-to-date.

Assuming those instructions are correct (which I maybe shouldn't assume), I tried to follow these instructions and do

    $ cd $(brew --prefix)
    $ rm cocot.rb

However, it said 'file doesn't exist' when I tried to rm cocot.rb

One thing I'm not sure about is the cd $(brew --prefix) Are those the exact words I type or do I have to replace prefix with something? the cd was successful, so I'm assuming it was correct -- it moved me into /usr/local, but there was no file to remove. Contents of /usr/local are

Cellar              clamXav             git             mysql               var Library             doc             heroku              mysql-5.5.15-osx10.6-x86_64 README.md           etc             include             rvm bin             foreman             lib             share

At any rate, do you know how I can fix the 'brew update'

Update: After removing the files according to favoretti's instructions and trying chown -R <your_username> $(brew --prefix)/.git, I got the following error running brew update

error: The following untracked working tree files would be overwritten by merge:
    Library/Aliases/gperftools
    Library/Aliases/hashdeep
    Library/Aliases/htop
    Library/Aliases/nodejs
    Library/Aliases/ocio
    Library/Aliases/oiio
    Library/Aliases/pgrep
    Library/Aliases/pkill
    Library/Aliases/qt4
    Library/Aliases/twolame
    Library/Aliases/wxwidgets
    Library/Contributions/cmds/brew-aspell-dictionaries
    Library/Contributions/cmds/brew-beer.rb
    Library/Contributions/cmds/brew-dirty.rb
    Library/Contributions/cmds/brew-graph
    Library/Contributions/cmds/brew-grep
    Library/Contributions/cmds/brew-leaves.rb
    Library/Contributions/cmds/brew-linkapps.rb
    Library/Contributions/cmds/brew-ls-taps.rb
    Library/Contributions/cmds/brew-man
    Library/Contributions/cmds/brew-md5-to-sha1
    Library/Contributions/cmds/brew-mirror-check.rb
    Library/Contributions/cmds/brew-pull.rb
    Library/Contributions/cmds/brew-readall.rb
    Library/Contributions/cmds/brew-server
    Library/Contributions/cmds/brew-services.rb
    Library/Contributions/cmds/brew-switch.rb
    Library/Contributions/cmds/brew-test-bot.rb
    Library/Contributions/cmds/brew-tests.rb
    Library/Contributions/cmds/brew-unpack.rb
    Library/Contributions/cmds/brew-which.rb
    Library/Contributions/cmds/git
    Library/Contributions/cmds/svn
    Library/ENV/4.3/apr-1-config
    Library/ENV/4.3/bsdmake
    Library/ENV/4.3/c++
    Library/ENV/4.3/c89
    Library/ENV/4.3/c99
    Library/ENV/4.3/cc
    Library/ENV/4.3/clang
    Library/ENV/4.3/clang++
    Library/ENV/4.3/cpp
    Library/ENV/4.3/g++
    Library/ENV/4.3/gcc
    Library/ENV/4.3/git
    Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.2
    Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.2
    Library/ENV/4.3/ld
    Library/ENV/4.3/llvm-g++
    Library/ENV/4.3/llvm-g++-4.2
    Library/ENV/4.3/llvm-gcc
    Library/ENV/4.3/llvm-gcc-4.2
    Library/ENV/4.3/make
    Library/ENV/4.3/mig
    Library/ENV/4.3/sed
    Library/ENV/4.3/svn
    Library/ENV/4.3/xcrun
    Library/ENV/libsuperenv.rb
    Library/ENV/pkgconfig/leopard/libcrypto.pc
    Library/ENV/pkgconfig/leopard/libcurl.pc
    Library/ENV/pkgconfig/mountain_lion/libcurl.pc
    Library/ENV/pkgconfig/mountain_lion/libexslt.pc
    Library/ENV/pkgconfig/mountain_lion/libxml-2.0.pc
    Library/ENV/pkgconfig/mountain_lion/libxslt.pc
    Library/Formula/abcl.rb
    Library/Formula/abcmidi.rb
    Library/Formula/aiccu.rb
    Library/Formula/akka.rb
    Library/Formula/alac.rb
    Library/Formula/alure.rb
    Library/Formula/appledoc.rb
    Library/Formula/arangodb.rb
    Library/Formula/argp-standalone.rb
    Library/Formula/argtable.rb
    Library/Formula/autopano-sift-c.rb
    Library/Formula/avian.rb
    Library/Formula/avidemux.rb
    Library/Formula/avro-cpp.rb
    Library/Formula/aws-cloudsearch.rb
    Library/Formula/aws-sns-cli.rb
    Library/Formula/backupninja.rb
    Library/Formula/bact.rb
    Library/Formula/bam.rb
    Library/Formula/basex.rb
    Library/Formula/berkeley-db4.rb
    Library/Formula/bind.rb
    Library/Formula/blazeblogger.rb
    Library/Formula/bochs.rb
    Library/Formula/boost149.rb
    Library/Formula/bsdconv.rb
    Library/Formula/bsdmake.rb
    Library/Formula/buildapp.rb
    Library/Formula/bup.rb
    Library/Formula/byacc.rb
    Library/Formula/cadubi.rb
    Library/Formula/camellia.rb
    Library/Formula/casperjs.rb
    Library/Formula/ccextractor.rb
    Library/Formula/cconv.rb
    Library/Formula/cdo.rb
    Library/Formula/cdpr.rb
    Library/Formula/cgvg.rb
    Library/Formula/checkstyle.rb
    Library/Formula/chordii.rb
    Library/Formula/chruby.rb
    Library/Formula/cifer.rb
    Library/Formula/clhep.rb
    Library/Formula/cntlm.rb
    Library/Formula/cocot.rb
    Library/Formula/cogl.rb
    Library/Formula/collada-dom.rb
    Library/Formula/crash.rb
    Library/Formula/crossroads.rb
    Library/Formula/crosstool-ng.rb
    Library/Formula/css-crush.rb
    Library/Formula/csync.rb
    Library/Formula/ctemplate.rb
    Library/Formula/curlftpfs.rb
    Library/Formula/cutter.rb
    Library/Formula/cvsutils.rb
    Library/Formula/darkstat.rb
    Library/Formula/darner.rb
    Library/Formula/dart.rb
    Library/Formula/dasm.rb
    Library/Formula/debianutils.rb
    Library/Formula/dfc.rb
    Library/Formula/dgtal.rb
    Library/Formula/dhcping.rb
    Library/Formula/di.rb
    Library/Formula/dmtx-utils.rb
    Library/Formula/drip.rb
    Library/Formula/dsniff.rb
    Library/Fo
Aborting
Updating e088818..c1fbc29
Error: Failed while executing git pull  origin refs/heads/master:refs/remotes/origin/master
github.com/Homebrew/homebrew-core - check the official README.md of Homebrew Core. There should be no need to adjust permissions as a few of the older answers recommend. Also check that you are pointed to the current official source url. More info in this answer: stackoverflow.com/questions/14113427/…

J
Jared Burrows

You need to do the following:

cd $(brew --prefix)
rm Library/Formula/argp-standalone.rb
rm Library/Formula/cocot.rb

And then do the

git fetch origin
git reset --hard origin/master
brew update

Basically, to explain a bit more:

cd $(brew --prefix)

tells cd to change the directory to whatever brew --prefix will output. If you try executing brew --prefix command you should see something in lines of:

brew --prefix
/usr/local

So the command would be in this case an equivalent of cd /usr/local. Newer brew versions have formulae under its installation prefix and Library/Formula/, so that's where you need to look for those outdated/changed files.

Note, that if you changed those formulae yourself for a particular reason (like pinning a version) this action will revert them back to default ones and may produce unwanted effects.

@TedPennings noted in comments that this worked for him, but his sequence was:

chown everything to my_username:admin, ie, sudo chown -R ted:admin $(brew --prefix) run the two git commands above,git fetch origin and git reset --hard origin/master


when I did git reset --hard origin/master, it seemed to only partially work. This is the output. error: unable to unlink old '.gitignore' (Permission denied) error: unable to create file CONTRIBUTING.md (Permission denied) Checking out files: 100% (2493/2493), done. fatal: Could not reset index file to revision 'origin/master'.
It means your permissions are screwed. One way would be to run sudo git reset --hard, other and a better way would be to fix permissions and do chown -R <your_username> $(brew --prefix)/.git
This is how permissions on my brew prefix look like here: drwxrwxr-x 16 root admin 646 Dec 27 20:30 /usr/local/
This solution fixed things for me, but I had to chown everything to my username:admin, ie, sudo chown -R ted:admin $(brew --prefix) and then run the two git commands above, git fetch origin and git reset --hard origin/master
@TedPennings: Cool! I'll add your commands to the answer as a possible additional step.
S
Strand McCutchen
cd $(brew --prefix)
git reset --hard HEAD
brew update

Had similar issue to the original question but with different conflicting files. Just resetting was sufficient to let me update and resolve the issue.
you might want to do also git add . followed by git stash :P
Works for me. Literally type this cd $(brew --prefix)
If, after changing to the brew directory with cd $(brew --prefix) and resetting the git stage with git reset --hard HEAD your git status does not return working directory clean you may also need to clean up the state by running git clean -df.
Instead of git reset --hard HEAD (which wouldn't work for me), I did git fetch --all and git reset --hard origin/master
E
Eric Wu

This is caused by an old bug in the update code that has long since been fixed. However, the nature of the bug requires that you do the following:

cd $(brew --repository)
git reset --hard FETCH_HEAD

If brew doctor still complains about uncommitted modifications, also run this command:

cd $(brew --repository)    
git clean -fd

This solution worked for me when the accepted answer did not.
R
Ron D.
$ cd $(brew --prefix)
$ git clean -fd
$ git reset --hard
$ sudo chown -R `whoami` `brew --prefix`
$ brew update

Note: steps 2&3 worked for me since I did step 5 before 4 before I got the error. The brew update before changing the owner of the folder caused the whole problem.


This worked for me. I would like to add that this is can be caused by other programs installing stuff in /usr/local with other permissions. For me it was MacPGP that installed itself with root privileges.
This fixed it for me after upgrading to Mac OS X 10.11 messed with /usr/local's permissions. Thanks!
It's worth noting that you may not need to change permissions and move directories manually. See stackoverflow.com/a/40599893/5440638, for example.
d
demesne

I had a similar issue where my brew package library got downloaded as a root user and then I was not able to run brew update as git would complain about not able to merge the file.

Solution was to do :-

sudo chown -R <user> /usr/local/Library

p
pstaender

Resetting the brew repository should be the most efficient way if you don't mind to discard potential modifications on formulas you might have been applied:

$ cd `brew --prefix`
$ git fetch origin
$ git reset --hard origin/master
$ brew cleanup --force
$ brew update

j
jimmont

I was able to fix this on my machine by adding admin group write (and setgid bit) permission at these paths:

sudo chmod -R g+ws /usr/local /Library/Caches/Homebrew

The s sets the group id on execution so that the write permissions aren't lost the next time a different admin user updates or upgrades Homebrew.

This answer is somewhat incomplete because when I try to do brew cleanup --force there is a permissions issue when Homebrew tries to remove content in /usr/local/Cellar/. (Unfortunately I'm not able to investigate this further at the moment.)


There is a popular script written to fix Homebrew permissions that apparently works quite well. I haven't needed to use it myself; I manually did the changes :) But this may help others: gist.github.com/rpavlik/768518
Q
Qantas 94 Heavy

Another option is to just use git stash.

The brew update command performs a git pull, so if there are any changed files (or even file attributes, which happened to me when I changed permissions in the directory recursively) you have to somehow fix the conflicts. Using git stash is one way; it takes any changes and puts them aside so you effectively revert to the last updated repo version. The Homebrew 'location' is by default /usr/local and it installs as a git repository. You can look for a .git folder to see for yourself. I'm writing a homebrew uninstall script to be posted on my GitHub profile soon with more info.


i
imvp
sudo chown -R USER /usr/local/bin

note - for USER use command whom i.e. your username

sudo brew doctor

or to generalize: sudo chown -R $USER /usr/local/bin where adding the $ posits the USER env variable, which holds the current USERname.
K
Kay V

This approach may be simpler than some. It involves:

fixing a git issue so you can delegate management of changes to it again.

no manual moves of files or directories.

no manual adjustments of file or directory permissions.

Steps (with notes for those who want explanations):

cd $(brew --repository)                              // see Note 1 below
git remote add brew https://github.com/Homebrew/brew // see Note 2 below
git pull brew master                                 // promising fast-forward report!
brew update                                          // see Note 3 below 

Overview:
From what I can tell, the actual cause of this issue is a change in the repo url. It's now brew and was brew.git. (Full up-to-date url: https://github.com/Homebrew/brew)

Note 1: This first command takes you from anywhere in your file structure to the correct directory. The directory structure is different for me than what others show above (Mac OS 10.11.16), but with this command, those differences should not matter.

Note 2: This second command adds the correct remote url to a new alias; I did so just in case this approach didn't accomplish what I wanted and I needed the previous address again. Since the new remote worked, I'll invite someone else to comment on simply changing the url aliased by origin. I'll happily update the answer to reflect what worked for you.

Note 3: This forth command has exactly the desired result: it reports a large number of updates, including the particularly nice report of "==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!" (emphasis theirs).


This works when you get 504 errors when running brew update.
c
clozach

This post helped me after updating to El Capitan. In my case, chown wasn't working ("zsh: command not found: chown"), so step 1 was adding this line to my .zshrc:

export PATH="$PATH:/usr/sbin"

I'd already tried several of the more popular answers above, so I'm pretty sure that git status was coming up clean by the time I pasted in the critical command from the blog post:

sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local


R
Rahul Vivek

This should work.

1. cd `brew --prefix`
2. git fetch origin
3. git reset --hard origin/master
4. sudo brew update

Fwiw, sudo is strongly discouraged when using homebrew. Note the down-votes on other answers to this question, as well as the warning homebrew helpfully provides when you enter a command using sudo. @A5308Y also provides a link to the FAQ about why sudo is bad; the latest version of that FAQ is at github.com/Homebrew/brew/blob/master/docs/… Have you tried following your steps without sudo?

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now