例えば仮になんですけど 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}
などとして回避。うーん。。。