Phillip
Phillip

Reputation: 5676

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

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?

Upvotes: 3

Views: 2000

Answers (3)

phd
phd

Reputation: 94827

Use git log instead:

git log --oneline --first-parent --format="%h %cd" HEAD

Upvotes: 1

Bauhaus
Bauhaus

Reputation: 519

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'

Upvotes: 4

Omer Tuchfeld
Omer Tuchfeld

Reputation: 3042

Kinda slow and not ideal but you can do something like this:

git rev-list --oneline --first-parent --reverse HEAD | awk '{cmd="git show -s --format=%ci "$1" | cat"; cmd | getline t; print $0 " " t}'

Upvotes: 0

Related Questions