Search code examples
gitversion-controlgit-branch

show git branches with date of last commit


I was working on a branch a couple of weeks ago but I can't remember what the branch was called (there are many). I'd like to be able to do something like:

git branch --print-last-commit

and for it to output something like:

branch 1 - 2017-02-12
branch 2 - 2016-12-30

etc.

Is there any way to do this?


Solution

  • This will print BranchName - CommitMessage - Date as (YYYY-MM-DD). You can manipulate/edit this command line to suit your need.

    git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:short)%(color:reset))'
    

    Note that it will print for all local branches, not just current branch. You can create an alias for convenience.

    [alias]
           branchcommits = !git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:short)%(color:reset))'
    

    and run git branchcommits in git bash prompt.

    enter image description here