Skip to content

Instantly share code, notes, and snippets.

@cibinmathew
Last active August 27, 2022 05:51
Show Gist options
  • Save cibinmathew/ee2005b806e5e67c5398ad10239bc2c3 to your computer and use it in GitHub Desktop.
Save cibinmathew/ee2005b806e5e67c5398ad10239bc2c3 to your computer and use it in GitHub Desktop.
fco_preview - checkout git branch/tag, with a preview showing the commits between the tag/branch and HEAD
# https://github.com/junegunn/fzf/wiki/Examples#git
# fco_preview - checkout git branch/tag, with a preview showing the commits between the tag/branch and HEAD
fco_preview() {
local tags branches target
branches=$(
git --no-pager branch --all \
--format="%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%1B[0;34;1mbranch%09%1B[m%(refname:short)%(end)%(end)" \
| sed '/^$/d') || return
tags=$(
git --no-pager tag | awk '{print "\x1b[35;1mtag\x1b[m\t" $1}') || return
target=$(
(echo "$branches"; echo "$tags") |
fzf --no-hscroll --no-multi -n 2 \
--ansi --preview="git --no-pager log -150 --pretty=format:%s '..{2}'") || return
git checkout $(awk '{print $2}' <<<"$target" )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment