List Recent git Commits from Command Line

By  on  

GitHub is an amazing service which brings the boring, sometimes difficult git command line tool to life.  Oftentimes instead of futzing with the command line I'll simply bring up GitHub and find what I need.  In the year 2016, however, I'm trying to break away from GUI crutches and learn more low level stuff.

One task I've been using GitHub for is a retrieving a list of recent commits to a repo -- especially useful at this type of year when I (and many others) were wasting away on vacation over the holidays.  I found a useful command for listing commits newest to oldest so on commandlinefu:

git log --oneline | nl -v0 | sed 's/^ \+/&HEAD~/'

That command will render a listing with the latest commits first and original commit last:

0	b0d9243 Merge pull request #119 from awalGarg/master
1	f0b7b87 Merge pull request #189 from delapuente/proxify-render-store
2	973476a Add proxy to images as well
3	986e9fe Merge pull request #188 from delapuente/proxify-render-store
4	7f7ae51 Adding proxy to allow mixed content

...

401	2813e25 Update README.md
402	1ec78c5 Create README.md
403	c2c95db Initial commit

Of course typing this each time would be a nightmare to remember so a custom command or alias would be in order!

Recent Features

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

  • By
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • By
    Retrieve Google Analytics Visits and PageViews with PHP

    Google Analytics is an outstanding website analytics tool that gives you way more information about your website than you probably need. Better to get more than you want than not enough, right? Anyways I check my website statistics more often than I should and...

  • By
    Basic AJAX Requests Using MooTools 1.2

    AJAX has become a huge part of the modern web and that wont change in the foreseeable future. MooTools has made AJAX so simple that a rookie developer can get their dynamic pages working in no time. Step 1: The XHTML Here we define two links...

Discussion

  1. Vladimir

    …or can simply use command “tig”. =)

  2. slash3b
    git log - - oneline - number of commits
  3. Chris McCoy

    nice one ;)

    here are some more handy git commands i have put together

    https://gist.github.com/chrismccoy/8775224

    • Dharm

      Hello Chris, I am a newbie to Git and to it’s commands. Very helpful commands. I have one requirement where I need the fetch the list of commit ids from the RELEASE branch created by a development branch. Assume is that the development branch has been checked in multiple times to the RELEASE based on the multiple requirements.

  4. We were once asked to note down what we did the whole day long.
    Defining an alias like:

    git config --global alias.today ‘shortlog --since=”1am” --no-merges’
    

    and then invoking

    git today
    

    eased that task :-)
    (It lists all commits since a.m. sorted by author and excludes possible merge requests thereby)

  5. Even more quickly and easily:

    gem install git-smart
    git smart-log
    
  6. I have an alias that lets me quickly look at the last 20 commits; use it all the time. In my .zshrc:

    gso='git log --oneline -20 --decorate'
    

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!