Git select ansestor based on commit date

25 Views Asked by At

I can do HEAD@{30d} to get where my HEAD was 30d ago. But this is based on the local reflog. It won't contain commits that I never checked out and may contain other branches that I switched to even if they were never merged into current HEAD.

Is there a way to do something similar but following the commit ancestry instead? I'm thinking something like HEAD~{30d} which would be interpreted as "walk the first parents of HEAD and return the first commit with a committed date older than 30 days old.

I want this because I frequently use git bisect to track down a problem, and often I don't know exactly when it started. So I want do something like git bisect HEAD HEAD~{30d} to look for a change in the last 30 days. Right now I am working around this by using git log to select the commit.

git bisect start HEAD $(git log -n1 --pretty=format:%H --before '30 days ago')

This works but is much less convenient. It seems surprising that there isn't a syntax for what seems like a common query.

1

There are 1 best solutions below

0
jthill On

git log -n1 --pretty=format:%H --before '30 days ago — works but is much less convenient.

You can do much better.

git rev-list -1 --before=30days @

and if you're doing it a lot you can make an alias, with some use of the option syntax flexibility,

git config --global alias.bef 'git rev-list -1 @ --before'

then git bef 30days prints it.

You might want to add --first-parent to avoid getting disoriented in thickly-branched ancestry.