Question

I have a bunch of files that I want to know which release they were introduced in. In bulk. The releases are tagged in git.

What's the easiest way to quickly check large (~80) number of files' presence in multiple (~10) tags ?

I can write some custom code to check out each tag to a directory, look for the files present on the file system, etc.

Is there a faster, more 'git' way to do that?

Thinking of git as a graph, I guess the pure implementation is to trace the history to the origin commit, then forward to the tags containing that commit. But, unless there is a tool already to do so, this is probably a more complicated approach than checking out the tag.

Was it helpful?

Solution

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.71 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 Added (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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top