LoginSignup
12
10

More than 5 years have passed since last update.

git 管理下のファイルを commit はしたくないけど手元で編集したままにしたい

Last updated at Posted at 2014-10-17

例えば仮になんですけど Android 開発をしているとして、local.properties を commit してしまってあるかなりアレなプロジェクトがあったとして、sdk.dir が自分の環境と違う、みたいなとき。

とりあえず commit の前後だけ置換すればいいんじゃね的な。
絶対もっといい方法はあるとは思うんですが、とりあえず動くには動く。

.git/hooks/pre-commit

pre-commit
#!/bin/sh

ours=自分の環境用のパスとか文字列
theirs=commit されているパスとか文字列
targetfile=対象のファイル

sed -i '' -e "s/${ours}/${theirs}/g" $targetfile
git add $targetfile

.git/hooks/post-commit

post-commit
#!/bin/sh

ours=自分の環境用のパスとか文字列
theirs=commit されているパスとか文字列
targetfile=対象のファイル

sed -i '' -e "s/${theirs}/${ours}/g" $targetfile

追記

これで概ね問題なく作業はできるのだけど、rebase 時には conflict 扱いになってしまって困る。

とりあえず rebase 前に

mv .git/hooks/{post-commit,post-commit.t}

終わったら

mv .git/hooks/{post-commit.t,post-commit}

などとして回避。うーん。。。

12
10
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10