In Pro Git Scott Chacon gives some nice examples of some alias which might be helpful, including one that shows the last commit: git last
which is the equivalent of log -1 HEAD
:
git config --global alias.last 'log -1 HEAD'
It will show something like this:
$ git last
commit 66938dae3329c7aebe598c2246a8e6af90d04646
Author: Josh Goebel <dreamer3@example.com>
Date: Tue Aug 26 19:48:51 2008 +0800
test for current head
I read a few similar questions on stack overflow like Pass an argument to a Git alias command but have not still not been able to figure this out.
The best I could come up with was to modify my .gitconfig
file as follows:
[alias]
last = log -1 HEAD
mylast = "!sh -c 'echo /usr/local/bin/git last -$0 HEAD'"
Then if I run this at the command line:
$ git mylast 12
I get this:
/usr/local/bin/git last -12 HEAD
That actually looks right. But if I remove the echo
in front, it just hangs like it is waiting for input. I tried switching $0
for $1
but that didn't seem to help either.
What am I doing wrong?
Also, is there a way to set it up so that if I just type git last
with no number then it would default to "1" ?