Skip to content

Instantly share code, notes, and snippets.

@bturrubiates
Created May 18, 2016 22:02
Show Gist options
  • Save bturrubiates/e015fd7159b61c6853ea9d75ec6a33e1 to your computer and use it in GitHub Desktop.
Save bturrubiates/e015fd7159b61c6853ea9d75ec6a33e1 to your computer and use it in GitHub Desktop.
FZF scripts to browse a git repo

Browsing a Git repo with FZF

Place this code in a file somewhere in $PATH. I place it in a script called git-fbr-files. The script takes an old revision and a new revision and will show individual files changed. Select the file with FZF and hit enter to view a diff.

#!/usr/bin/env zsh

old="$1"
new="$2"

git diff --name-status --relative $old $new |
fzf --reverse --bind="ctrl-m:execute:(echo {} | cut -f 2 |
        xargs -I % git diff --patience --color=always $old $new -- % | less -R)"

This script depends on the script above. If you put it in a file called something other than git-fbr-files make sure to update. Run in a git repository to see a graph of the commits. Select a commit and hit enter to see the commit diff, hit ctrl-b to break it down by file.

#!/usr/bin/env zsh

git log --graph --color=always                                                 \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
fzf --ansi --no-sort --reverse --tiebreak=index                                \
        --bind="ctrl-s:toggle-sort"                                            \
        --bind="ctrl-m:execute:(echo {} | grep -o '[a-f0-9]\{7\}' | head -1 |
                xargs -I % git show --patience --color=always % | less -R)"    \
        --bind="ctrl-b:execute:(echo {} | grep -o '[a-f0-9]\{7\}' |
                xargs -I % git fbr-files %^ %)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment