We can already use --graph
and --decorate
to get a pretty, colored commit tree, but we can create a function for less typing, more flexibility and more info:
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
# Short for git decorated log
gdl() {
branches=''
if [ -n "$1" ] && [ -n "$2" ]; then
branches=$1..$2
elif [ -n "$1" ]; then
if [ $1 == "keyword" ]; then
branches="$(git_branch)"
else
branches=$1.."$(git_branch)"
fi
else
branches=master.."$(git_branch)"
fi
git log --oneline --graph --decorate $branches
echo "${blue}Difference: ${green}$(git rev-list --count $branches) commits."
}
This will also print the number of commits between the two branches at the end, and the rules are as follows:
keyword
(make sure it's something unique), ormaster
) and the current branch.The color helpers can be found here.