January 29, 2013

git me and git wholog - useful git aliases for viewing commits

When using git, it is a common requirement to be able to get a log of all the commits that you have done or some one else has done. I find the git --committer a little long to type in and use every time, with a little bash-foo you can have simple aliases like "git me" and "git wholog " to do the same. The changes for this would be : 

$HOME/bin/git

#!/bin/bash

if [ $# -gt 0 ]; then
        if [ "$1" == "me" ]; then
                exec git log --committer='Satish'
        elif [ "$1" == "wholog" ]; then
                if [ $# -lt 2 ]; then
                        echo "usage: git wholog "
                        exit 1
                fi
                exec git log --committer=$2
        else
                exec git $@
        fi
fi

$HOME/.bashrc

alias git='~/bin/git`


Run "source ~/.bashrc" and you are all set to go.

In retrospect, this could have been done much more neatly with "git config --global alias.xxxx".

2 comments:

  1. There is a simpler way to do it.
    Creating a script `git-anything` will let you execute `git anything`!

    $vim git-me
    git log --committer='Satish'

    put it in /usr/bin

    $ git me # and it works

    ReplyDelete
  2. I would not put a user specific alias in a system folder and also, I still think using the git alias functionality is a cleaner way of doing this.

    ReplyDelete