4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windowsのgitと文字コードについて

Posted at

Git for Windowsで、BOM付きUTF-16のテキストファイルを使用すると、gitにファイルがBinaryとして扱われてしまい、デフォルトの状態で以下の問題がある。

  • git diff でdiffを見たときに、Binary files differ と表示され、差分の内容を見ることができない。
  • git merge, git rebase を実行すると、修正した場所が別の所でも、CONFLICTが発生し、Automatic merge failedになる。

そこで、普段使いそうな文字コードでファイルを作成し、それぞれがどのように扱われるかを見てみた。

文字コード 扱い diff merge/rebase
CP932 text 文字化けする 成功する
UTF-8(BOM無し) text 文字化けしない 成功する
UTF-8(BOM付き) text 文字化けしない 成功する
UTF-16LE(BOM無し) binary - 失敗する
UTF-16LE(BOM付き) binary - 失敗する

.gitattributes等はない状態での話です。

4
2
0

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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?