DEV Community

r_tanaka
r_tanaka

Posted on • Edited on

How to use terminal to make git diff beautiful

Hi, terminal folks!

There is the word diff feature in git.
Let's activate it now!

First, my git version is this.

$ git version
git version 2.21.0

It is essential to make a diff-highlight binary file.
Then move it to executable path or create a symbolic link for same purpose.
However, initial state of the binary is different depends on each linuxs.
there are 3 patterns as far as I know.

  1. a binary exists with an executable permission
  2. a binary exists with a not-executable permission
  3. there is a make file instead of a binary

I write just for option#3. If your initial state is #1 or #2, please make sure it works by reading below. I guess you can do it.

cd /usr/share/doc/git/contrib/diff-highlight/
sudo make
sudo ln -s /usr/share/doc/git/contrib/diff-highlight/diff-highlight /usr/local/bin/diff-highlight
sudo chmod +x /usr/share/doc/git/contrib/diff-highlight/diff-highlight

At last, edit your ~/.gitconfig file

[core]
    pager = diff-highlight | less -r

Top comments (0)