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?
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'
Use git log instead:
git log --oneline --first-parent --format="%h %cd" HEAD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With