I came across Jvns’ fzf
Git commit preview
post which explores using a lightweight, local git review client using fzf
which caught my interest.
So I tweaked the setup to suit my needs — especially to add a scrollable diff preview window!
0. Install Fuzzy Finder (fzf
)
if you haven’t already, install fzf
using Homebrew:
brew install fzf
1. Define a bash function gitdiff
in .zshrc
append this function to your .zshrc
(or relevant shell config file):
gitdiff() {
commit=${1:-HEAD}
git show -m --stat=120 --format="" "$commit" | \
grep '|' | \
fzf --ansi \
--disabled \
--bind 'j:down,k:up,q:abort' \
--bind 'ctrl-j:preview-down,ctrl-k:preview-up' \
--preview="echo {} | sed 's/ *|.*//' | xargs -I% git show --color=always $commit -- %" \
--preview-window=right:60%
}
then, source the file:
source ~/.zshrc
1.5. Confirm It’s Set Up Correctly
which gitdiff
you should see the function definition printed like this:
gitdiff () {
commit=${1:-HEAD}
git show -m --stat=120 --format="" "$commit" | grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox,.venv,venv} '|' | fzf --ansi --disabled --bind 'j:down,k:up,q:abort' --bind 'ctrl-j:preview-down,ctrl-k:preview-up' --preview="echo {} | sed 's/ *|.*//' | xargs -I% git show --color=always $commit -- %" --preview-window=right:60%
}
2. Navigate to any Git repo and run:
gitdiff <commit-hash>
you can now not only scroll files but scroll changes as well using ctrl + j/k
to scroll code changes down/up respectively