19
15

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.

diff-so-fancyでgit diff を見やすくする

Last updated at Posted at 2016-03-28

gitのdiffを見やすくするツールをご紹介

diff-so-fancy

so-fancy/diff-so-fancy: Good-lookin' diffs with diff-highlight and more
diff-so-fancy

diff-so-fancy builds on the good-lookin' output of git contrib's diff-highlight to upgrade your diffs' appearances.
・Output will not be in standard patch format, but will be readable.
・No pesky + or - at line-start, making for easier copy-paste.

fancy.png
:arrow_up: diff-so-fancy
:arrow_down: 通常
normal.png

インストール

npm

npm install -g diff-so-fancy

Homebrew

brew update
brew install diff-so-fancy

使い方

常時利用

git configで設定し、常時利用

# タブ幅はお気に入りの設定で
git config --global pager.diff "diff-so-fancy | less --tabs=4 -RFX"
git config --global pager.show "diff-so-fancy | less --tabs=4 -RFX"

今まで通り表示したい場合は

git --no-pager diff

一時利用

git diff --color | diff-so-fancy

別コマンドで

git dsfとする場合、~/.gitconfigに以下を追記

~/.gitconfig
dsf = "!f() { [ \"$GIT_PREFIX\" != \"\" ] && cd "$GIT_PREFIX"; git diff --color $@ | diff-so-fancy | less --tabs=4 -RFX; }; f"

ハイライト設定

差分の色を変えたい場合は以下の設定を変更

git config --global color.diff-highlight.oldNormal "red bold"
git config --global color.diff-highlight.oldHighlight "red bold 52"
git config --global color.diff-highlight.newNormal "green bold"
git config --global color.diff-highlight.newHighlight "green bold 22"

Tips

どちらかというとlessのTipsだが以下の設定を行うことでファイル間の移動が簡単になる。
nキーで次のファイル、pキーで前のファイル

git config --global pager.diff "diff-so-fancy | less --tabs=4 -RFX --pattern='^(added|deleted|modified): '"
19
15
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
19
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?