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

后端 未结 12 768
旧巷少年郎
旧巷少年郎 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:29

    This should work.

    1. cd `brew --prefix`
    2. git fetch origin
    3. git reset --hard origin/master
    4. sudo brew update
    
    0 讨论(0)
  • 2020-12-12 09:32

    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.

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

    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
    
    0 讨论(0)
  • 2020-12-12 09:38
    cd $(brew --prefix)
    git reset --hard HEAD
    brew update
    
    0 讨论(0)
  • 2020-12-12 09:43

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

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

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

    0 讨论(0)
提交回复
热议问题