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

后端 未结 12 767
旧巷少年郎
旧巷少年郎 2020-12-12 09:03

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

error: The following untracked working tree files would be overwrittenby me         


        
相关标签:
12条回答
  • 2020-12-12 09:19
    $ 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.

    0 讨论(0)
  • 2020-12-12 09:21

    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
    
    0 讨论(0)
  • 2020-12-12 09:22

    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
    
    0 讨论(0)
  • 2020-12-12 09:22
    sudo chown -R USER /usr/local/bin
    

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

    sudo brew doctor
    
    0 讨论(0)
  • 2020-12-12 09:22

    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

    0 讨论(0)
  • 2020-12-12 09:23

    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:

    1. chown everything to my_username:admin, ie, sudo chown -R ted:admin $(brew --prefix)
    2. run the two git commands above,git fetch origin and git reset --hard origin/master
    0 讨论(0)
提交回复
热议问题