Skip to contentSkip to conversation

referencing a revision at a certain date

DISCUSSION David Madore 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

I'm left quite confused by the git-rev-parse(1) man page, I wonder if someone can help me with this.

I understand that if "rev" denotes a certain revision, then "rev~42" references the commit which is 42 generations back from rev. What I'd like to do is write something like "rev~@{2008-01-18}" (say) to get the same thing but with the 42 being computed automatically so that the commit in question is the latest possible (in commit date) before 2008-01-18. Is this possible? If so, how? If not, might I suggest this as an addition for consideration?

I thought "rev@{2008-01-18}" did this, but apparently it doesn't: it requires a ref log of some kind, and I don't know how to make a ref log (git-clone doesn't seem to copy them).

So, is there some way I can either generate a ref log by systematically taking the first parent in each commit as per git-log --first-parent, OR (better) specify a revision directly that way?

Typical problem I'm faced with:

mizar david /tmp $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Initialized empty Git repository in /tmp/linux-2.6/.git/
remote: Counting objects: 712898, done.
remote: Compressing objects: 100% (124199/124199), done.
Indexing 712898 objects...
remote: Total 712898 (delta 591709), reused 708828 (delta 587713)
100% (712898/712898) done
Resolving 591709 deltas...
100% (591709/591709) done
Checking 23757 files out...
100% (23757/23757) done
mizar david /tmp $ cd linux-2.6
mizar david /tmp/linux-2.6 $ git rev-parse 'master@{2008-02-01}'
warning: Log for 'master' only goes back to Mon, 11 Feb 2008 18:34:33 +0100. 0000000000000000000000000000000000000000
mizar david /tmp/linux-2.6 $ git rev-parse 'origin@{2008-02-01}'
warning: Log for 'origin' only goes back to Mon, 11 Feb 2008 18:34:32 +0100. 0000000000000000000000000000000000000000
mizar david /tmp/linux-2.6 $ git cat-file -p 'master~1126' | head -5
tree a72dadd4a8b4957a4e21bf7ae38a763a71d6e274
parent e1a9c9872dd004617555dff079b357a6ffd945e9
parent c4772d99300a9fc13c86aaa370e630c5973664f6
author Linus Torvalds <[email protected]> 1201821909 +1100
committer Linus Torvalds <[email protected]> 1201821909 +1100

=> there must be some intelligent way of finding this revision, but which is it?

Cheers,

Signature · 3 lines
     David A. Madore
    ([email protected],
     http://www.madore.org/~david/ )
#1 lore raw
Quoted 7 lines · David Madore

I understand that if "rev" denotes a certain revision, then "rev~42" references the commit which is 42 generations back from rev. What I'd like to do is write something like "rev~@{2008-01-18}" (say) to get the same thing but with the 42 being computed automatically so that the commit in question is the latest possible (in commit date) before 2008-01-18. Is this possible? If so, how? If not, might I suggest this as an addition for consideration?

How about --before=2008-01-18? As in,

  git log --before=2008-01-18

to start your log there (and "git log -1 --before=2008-01-18" if you just want that one commit).

Quoted 3 lines

I thought "rev@{2008-01-18}" did this, but apparently it doesn't: it requires a ref log of some kind, and I don't know how to make a ref log (git-clone doesn't seem to copy them).

Ref logs are a log of where your particular, local ref was pointing to. In other words, it is a history not of the project commits, but of an individual branch in your local repository. So you don't ask the reflog things like "which commit has a date at X" but rather "where was my master branch pointing at 3pm yesterday?"

And because they are purely a local matter, they don't get copied by clone.

Quoted 3 lines

So, is there some way I can either generate a ref log by systematically taking the first parent in each commit as per git-log --first-parent, OR (better) specify a revision directly that way?

So this question doesn't really make sense. You generate a ref log by doing operations on a branch.

-Peff

#2 lore raw
In reply to David Madore
Quoted 5 lines · David Madore

I'm left quite confused by the git-rev-parse(1) man page, I wonder if someone can help me with this.

I understand that if "rev" denotes a certain revision, then "rev~42" references the commit which is 42 generations back from rev.

To be more exact it is 42 generations in straight, first-parent line. rev~3 is shortcut to rev^^^, which is shortcut to rev^1^1^1, where rev^1 means 1st parent of rev.

Quoted 6 lines

What I'd
like to do is write something like "rev~@{2008-01-18}" (say) to get the same thing but with the 42 being computed automatically so that the commit in question is the latest possible (in commit date) before 2008-01-18. Is this possible? If so, how? If not, might I suggest this as an addition for consideration?

There is no direct mapping from date to a commit. So you cannot name a commit (specify a revision) using date. Besides commit has two dates:
author date (creation date), and commit date (modification date, roughly).

But you can can get commit closest to given date by combining the time limiting with limiting number of commits, as described in "Commit limiting" in git-rev-list(1) and git-log(1) manpages.

  $ git log -n 1 --before=<date> <branch>

which would return first commit older than <date>, starting from <branch>.

Quoted 3 lines

I thought "rev@{2008-01-18}" did this, but apparently it doesn't: it requires a ref log of some kind, and I don't know how to make a ref log (git-clone doesn't seem to copy them).

Reflogs are history (log) of a position of branch tip (ref) in a local repository. Reflog stores sha-1 of top commit before and after change, date of change, and description of command that changed it. For example <branch>@{1} refers to position of branch before you did something locally to change it, were it commit, amending a commit, or for example fetching from remote repository.

Quoted 3 lines

So, is there some way I can either generate a ref log by systematically taking the first parent in each commit as per git-log --first-parent, OR (better) specify a revision directly that way?

Again: you cannot specify a commit in such way. You can find a (series of) commits which fulfill given condition.

HTH

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#3 lore raw
Quoted 8 lines · Jakub Narebski

But you can can get commit closest to given date by combining the time limiting with limiting number of commits, as described in "Commit limiting" in git-rev-list(1) and git-log(1) manpages.

  $ git log -n 1 --before=<date> <branch>

which would return first commit older than <date>, starting from <branch>.

OK, thanks, I guess the --before part answers my question: so to get revision "rev" back at date "YYYY-MM-DD" (always using first parents) I'd do

git rev-list rev -n 1 --first-parent --before=YYYY-MM-DD

as in:

git checkout "git rev-list rev -n 1 --first-parent --before=YYYY-MM-DD"

It's a bit of a mouthful, but it does what I want (although I still think a syntax such as rev~@{YYYY-MM-DD} or rev~{YYYY-MM-DD} or whatever might prove useful: I imagine I'm not the first person to wish for something of the sort).

Thanks,

Signature · 3 lines
     David A. Madore
    ([email protected],
     http://www.madore.org/~david/ )