Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show the commit date when using git rev-list --oneline?

Tags:

git

I'm trying to get a listing of the commits + commit date for a branch with:

git rev-list --oneline --first-parent --date=short --reverse HEAD

From the documentation, showing a date requires --pretty format, which outputs multiple lines. How can I show the commit date when using the --oneline option?

like image 901
Phillip Avatar asked Nov 27 '25 10:11

Phillip


2 Answers

Git provides multiple formatting options that you can pass to the pretty command to pick out the different pieces of the commit you want to display

For instance if you just want to grab the shortened commit hash (%H for the full commit hash) you could use:

git rev-list --pretty='format:%h' HEAD

To add the commit subject:

git rev-list --pretty='format:%h %s' HEAD

And the shortened date:

git rev-list --pretty='format:%h %s %ad' --date=short HEAD

You can also add some pretty color formatting if you wish:

git rev-list --pretty='format:%C(auto)%h %s %ad' --date=short HEAD

All of which is just C style string formatting so you can add pipes or commas as you see fit:

git rev-list --pretty='format:%C(auto)%h | %s | %ad' --date=short HEAD

To remove the intermediate line containing the full commit hash you can pipe the output to sed/awk:

git rev-list --pretty='format:%C(auto)%h | %s | %ad' --first-parent --reverse --date=short HEAD | awk 'NR%2==0'

like image 178
Bauhaus Avatar answered Nov 29 '25 01:11

Bauhaus


Use git log instead:

git log --oneline --first-parent --format="%h %cd" HEAD
like image 38
phd Avatar answered Nov 29 '25 00:11

phd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!