Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:18:35+00:00 2026-05-30T19:18:35+00:00

In Pro Git Scott Chacon gives some nice examples of some alias which might

  • 0

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” ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:18:37+00:00Added an answer on May 30, 2026 at 7:18 pm
    last = !sh -c 'git log "-${1:-1}" HEAD' -
    

    This takes advantage of the shell parameter interpolation default syntax, ${var:-default} which substitutes default if the variable var is not set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based on the Pro Git book by Scott Chacon on page 9, to install
Why on all images that show queue of commits in Pro Git book arrows
In Pro Git the author says that Git staging is just a file storing
So, from what I've read in Pro Git, It turns out that Git stages
In VisualStudio (Pro 2008), I have just noticed some inconsistent behaviour and wondered if
What does Pro have that's not in Standard (or vice-versa)? I need Visual Studio
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
So i've got something like this for a repository atm. D-Hewards-MacBook-Pro:project dheward$ git branch
I recently upgraded my MacBook Pro to Snow Leopard and git pull returns: rakudo
I understand that git diff compares a staged file and modified but not staged

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.