homebrewで編集してしまったFormulaを元に戻す方法
brew edit
で何らかのFormulaを変更した後、brew updateをするとエラーになります。
エラーの具合
こんな感じです。
$ brew update remote: Counting objects: 328, done. remote: Compressing objects: 100% (176/176), done. remote: Total 285 (delta 204), reused 181 (delta 109) Receiving objects: 100% (285/285), 34.50 KiB, done. Resolving deltas: 100% (204/204), completed with 36 local objects. From https://github.com/mxcl/homebrew ec21973..ab7067c master -> origin/master error: Your local changes to the following files would be overwritten by merge: Library/Formula/ghostscript.rb Please, commit your changes or stash them before you can merge. Aborting Updating ec21973..ab7067c Error: Failed while executing git pull origin refs/heads/master:refs/remotes/origin/master
対処方法その1
編集した内容をすべて無かったことにして、homebrew 本家の内容にするには:
cd /usr/local git checkout .
必ずhomebrewの.gitがある位置(=/usr/local)で、かつ、checkout のあとのドット . を忘れないで下さい。
この状態でbrew updateすると:
$ brew update Updated Homebrew from ec219733 to ab7067c9. ==> New formulae apollo gnu-arch oath-toolkit pulledpork cbmbasic libkate primesieve xplanet ==> Removed formulae pngwriter ==> Updated formulae armadillo ghostscript* libmagic pari xaw3d* binwalk gradle libplist qemu zile bwm-ng gtk+ libvirt qimageblitz zsh cc65 help2man nmap redis d-bus* icarus-verilog notmuch sonar ffmpeg2theora kes open-mpi tidyp
Update出来ましたね。
対処方法その2
特定のファイルだけ戻す場合:
cd /usr/local git checkout ファイル名 # e.g. git checkout Library/Formula/ghostscript.rb
対処方法その3
homebrew本家の最新を取り込んだ後で、編集したFormulaをマージしたい場合:
cd /usr/local git pull --rebase origin master
この場合はbrew updateしなくていいですね。