Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 963
Derek Ekins Avatar asked Jun 12 '17 08:06

Derek Ekins


People also ask

Which branch is used to see the last commit on each branch?

The HEAD points out the last commit in the current checkout branch. It is like a pointer to any reference. The HEAD can be understood as the "current branch." When you switch branches with 'checkout,' the HEAD is transferred to the new branch.


1 Answers

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

like image 163
Saurav Sahu Avatar answered Nov 08 '22 03:11

Saurav Sahu