git tag --contains <commit>
prints all the tags that are "at or downstream of" the given commit. You then need only pick the "first" such tag (if your tags are numbered simply, e.g., v1.7
v1.8
v2.0
that's probably trivial, if they're complicated like v1.7a
v1.7alpha
v1.7-0
v1.7.0
v1.7
1 then you'll need some other way to pick the right one, such as minimizing the graph "distance" from all the candidate tags).
git log --pretty=format:%H --diff-filter=A -1 -- path
prints the first commit-ID in which the given path
is A
dded (you might want --no-renames
, or maybe a specific -M
level and/or -C
options, to tweak whether git might consider a file renamed or copied, in terms of finding the commit).
Combining these two will get you there pretty quickly, I think.
1I just made these up and I still have no idea whether v1.7
comes before or after v1.7.0
here, nor what relation v1.7-0
and v1.7a
have to those two. I've seen crazy stuff like this "for real" before—usually after Marketing gets their hands on things—although I made this up just for illustration.