gitignore.ioを使うのが楽っぽいので、以下のようにする。
curl -L http://gitignore.io/api/windows,visualstudio > .gitignore
core.quotepathをfalseにすれば、文字化けは発生しない。 (参考: http://dev.classmethod.jp/tool/git/git-avoid-illegal-charactor-tips/ )
git config --local core.quotepath false
gitにはCRLFのまま保存しておくのがよさそうなので、core.autocrlf=falseにする。 ただ、そうすると、diffしたときに行末に「^M」が見えてしまうので、core.whitespace=cr-at-eolも設定する。 (参考: http://deadcode.hatenablog.jp/entry/2014/04/24/152135 )
git config --local core.autocrlf false
git config --local core.whitespace cr-at-eol
Visual Studioで作成されるファイルのデフォルトエンコーディングがSJISなので、これを文字化けしないようにする。 エンコーディングをUTF-8にできるならそっちの方がよいと思うけど、過去の文化とかあるからなかなか難しい。。。
そんなわけで、以下のように.gitattributeとdiff.*.textconvを設定すればよい。 (参考: http://qiita.com/mather314/items/a6b4bad59e2edd659dd4 )
.gitattributeというファイルを作成し、以下のように設定。
*.vb diff=sjis
*.cs diff=sjis
んで、iconvでSJISにコード変換する処理を間に挟む。
git config --local diff.sjis.textconv "iconv -f sjis"
以下のコマンドを実行すればOK。
curl -L http://gitignore.io/api/windows,visualstudio > .gitignore
git config --local core.quotepath false
git config --local core.autocrlf false
git config --local core.whitespace cr-at-eol
curl -L https://gist.githubusercontent.com/momo-lab/976c2bd68467a39ec2cbdb4ec25240a2/raw/gitattributes > .gitattributes
git config --local diff.sjis.textconv "iconv -f sjis"
- git diffは文字化けしないけど、git add -pのdiffが文字化けしてしまう。