Getting the git tags that are before and after a commit (in simple cases)
When I investigate something in a code base, I often wind up wanting
to know when a particular change became available in a release, or
in general to know when it was made in terms not of time but of
releases. Using release dates is both not reliable (since a change
can land early in a side branch and then be merged into mainline
only much later) and a certain amount of pain (you have to look up
release dates somewhere). For git-based projects, my general approach
so far has been to fire up gitk
, put in the SHA1 of the commit I
care about, and see what gitk says it was Before and After.
As it turns out, there is a better way to do this with Git command
line tools, with 'git describe
'
(as I found out when I bothered to do some Internet searches). For
my future reference, the two commands I want to get the tag before
and after a commit are:
; git describe f3a7f6610f zfs-0.6.3-49-gf3a7f6610 ; git describe --contains f3a7f6610f zfs-0.6.4~197
I was already sort of familiar with the first form of 'git describe', because various projects I build use it to automatically generate identifiers for what I'm building. The second form is new to me, as is the '~<count>' that means 'so many commits before tag <X>'.
I imagine that there are all sorts of complex git tree states that can make this question harder to answer. Fortunately I don't think I deal with any projects that might give me that sort of heartburn; the ones where I care about this question like relatively linear git histories.
PS: I don't know how git is establishing what tag is the most recent before a commit or the first after one, but I trust it to basically work. This is where I start having to look up the difference between plain tags and annotated tags, and other stuff like that (cf).
|
|