This is a quick tutorial that shows you how to set up logs for Git that will only display commits from your current branch!
First, you'll need to set up a helper file that contains some Bash functions
that Git will use. I placed mine in .githelpers
.
Here are the scripts you'll need. If you use a different format, remove the --pretty=colored
argument, or change colored
to the name of the format you use.
git_pretty_log() {
retrieve_branch_parent | \
xargs -I{} git log {}.. --pretty=colored --date=short --no-merges
}
retrieve_branch_parent() {
branch=`git rev-parse --abbrev-ref HEAD`
git show-branch -a 2>/dev/null | \
grep '\*' | \
grep -v "$branch" | \
head -n1 | \
sed 's/.*\[\(.*\)\].*/\1/' | \
sed 's/[\^~].*//'
}
After you've added the code, you'll need to set up the alias in your .gitconfig
file.
I organized mine like this (I use cl
as an abbreviation for "colored log"):
[alias]
cl = "!. ~/.githelpers && git_pretty_log"
If you want to use my log format:
[pretty]
colored = format:%C(yellow)%h %C(red)%ad %C(blue)%an %C(reset)%s
That's all you should need! You can now use the command like $ git cl
.