Created
November 19, 2015 15:35
-
-
Save mislav/4452431b8985d8b2ee8b to your computer and use it in GitHub Desktop.
Show list of recently checked-out branches in reverse-chronological order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD | { | |
seen=":" | |
git_dir="$(git rev-parse --git-dir)" | |
while read line; do | |
date="${line%%|*}" | |
branch="${line##* }" | |
if ! [[ $seen == *:"${branch}":* ]]; then | |
seen="${seen}${branch}:" | |
if [ -f "${git_dir}/refs/heads/${branch}" ]; then | |
printf "%s\t%s\n" "$date" "$branch" | |
fi | |
fi | |
done | |
} |
This has a bug somewhere, as it regularly misses branches of mine. I've increased it to -n10000
to ensure that failing to look far enough back into the reflog is not the source of the problem. If I find the bug I'll post back here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LOVE IT! Thanks