10
7

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.

異なる文字コードのファイルが混在するリポジトリでのgit diff +diff-highlight + nkf

Last updated at Posted at 2014-06-05

gitconfig

リポジトリに EUC-JP とか UTF-8 とかのファイルが混じっていると差分見たときに辛い。

そこで $HOME/.gitconfig に以下の設定をする

~/.gitconfig
[color]
        ui = true
[pager]
        diff = diff-highlight | nkf -w | LESS=-R less
        log = diff-highlight | nkf -w | LESS=-R less
        show = diff-highlight | nkf -w | LESS=-R less

こうしておくと差分見たときに そこそこ 幸せになれる。

git-diff
% git diff
diff --git a/hello.EUCJP.pl b/hello.EUCJP.pl
index 831a5e5..dd0cc07 100644
--- a/hello.EUCJP.pl
+++ b/hello.EUCJP.pl
@@ -2,4 +2,4 @@
 use strict;
 use warnings;

-print "日本が平和でありますように\n";
+print "世界が平和でありますように\n";
diff --git a/hello.UTF8.pl b/hello.UTF8.pl
index f522ad3..b2d099f 100644
--- a/hello.UTF8.pl
+++ b/hello.UTF8.pl
@@ -4,4 +4,4 @@ use warnings;
 use utf8;
 use Encode qw( encode );

-print encode( 'utf-8', "日本が平和でありますように\n" );
+print encode( 'utf-8', "世界が平和でありますように\n" );

一つ目は EUC-JP で、二つ目が UTF-8 のファイル。
なんで異なる文字コードのファイルが混ざっているかは歴史的経緯。

diff-highlight

ここから取ってくる。

10
7
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
10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?