Skip to content

Instantly share code, notes, and snippets.

@GregKWhite
Created May 24, 2016 19:06
Show Gist options
  • Save GregKWhite/68c158da225045c2618dba8716c06ee6 to your computer and use it in GitHub Desktop.
Save GregKWhite/68c158da225045c2618dba8716c06ee6 to your computer and use it in GitHub Desktop.

Fancy Git Logs

This is a quick tutorial that shows you how to set up logs for Git that will only display commits from your current branch!

Instructions

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment