Reputation: 1389
I need to print the latest 10 commits that are older than a specific date with specific format. I need to handle the date, obtained through the bash command:
date +"%Y%m%d%H%M"
I tried some options, but so far nothing
e.g.: git log -5 --no-merges --format=format:%cd --after=201506301524
Upvotes: 3
Views: 2801
Reputation: 3405
You need to use --until
instead of --after
and furthermore, the correct date format, but you can use date
to convert it:
git log --no-merges --format=format:%cd -10 --until "$(date -d "$(echo "201506301524" | sed 's/....$/ &/')")"
$(echo "201506301524" | sed 's/....$/ &/')
converts
the date to 20150630 1524
which is a valid input format for date.
Upvotes: 1
Reputation: 68790
First, you need to use the right date format (date +"%Y-%m-%d %H:%M:00"
):
git log --no-merges --format=format:%cd --after="2015-06-30 15:24:00"
Now, you can use --reverse
to get oldest commits first:
git log --reverse --no-merges --format=format:%cd --after="2015-06-30 15:24:00"
Unfortunately, git log --reverse -10
won't return what you want, as it'll grap the 10 latest commits, then reverse the list (which means you'll get the same list, whatever the specified date).
An alternative is to use head
on this result:
git log --reverse --no-merges --format=format:%cd --after="2015-06-30 15:24:00" | head -10
Upvotes: 0
Reputation: 27844
You have to format the date, only numbers won't do. Use one of those:
--after=2015-06-30-15:24:00
--after=2015-06-30:16:24:00
--after="2015-06-30 16:24:00"
All of those formats were accepted.
Upvotes: 2