Skip to content

Git diff side by side

kena edited this page Mar 17, 2016 · 1 revision

How to get a side by side diff with git diff in the terminal.

Requirements:

  • sdiff (from diffutils)
  • colordiff

Place the following in your PATH (eg ~/bin/diffy):

#!/bin/sh
echo
echo Comparing: "$1 between $3 and $6"
echo
if stty >/dev/null 2>&1; then
  pager=${PAGER:-less -r}
else
  pager=cat
fi
C=$(stty size | cut -d' ' -f2)
D=$(expr $C / 2)
sdiff -W -w $C "$2" "$5" | colordiff | grep -E "^.{$D} *[|<>] *" -A 10 -B 10 -n | $pager

Then set the environment variable GIT_EXTERNAL_DIFF to point to it.

Example output: Example screen shot

  • Home
  • Beta Dashboard
  • Release Process
  • [Building and running tests](Building and running tests)
    • [Using musl to get a completely static binary](Using musl to get a completely static binary)
  • Productivity
    • [Multiple GOPATHs](Multiple GOPATHs)
    • [Ben's Go Emacs setup](Ben's Go Emacs setup)
    • [Radu's vim setup](Radu's vim setup)
    • [Speeding up cgo builds](Speeding up cgo builds)
    • [Rando scripts](Rando scripts)
  • [Life of a transaction](Life of a transaction)
  • Readings
Clone this wiki locally