
Today's post is a quick tutorial how to use "git grep" and "git tag" to find the earliest tag that contains a particular line of code.
TL;DR: use:
git grep <regexp> $(git rev-list --all)
and
git tag --contains=<commit hash>
The Longer Version
In this case, I want to find the earliest tag that includes a given update function (stanford_courses_update_7300() in the Stanford Courses Drupal Module).
I'll first search for all commits that include the text "update_7300" (that string is specific enough that it will return only stanford_courses_update_7300):
% git grep update_7300 $(git rev-list --all)
That outputs a list of every commit that contains the text "update_7300" (which is a lot in this case). I can hit my spacebar to scroll through the list; I'm looking for the last commit in the list (i.e., the earliest commit that contains that code):
1cb28cee3c09ecee0208b3d25650a2e4d1a16a63:stanford_courses.install:function stanford_courses_update_7300(&$sandbox) {
I've found my commit hash; now I want to find the earliest tag that includes that commit:
7.x-3.1
7.x-3.10
7.x-3.2
7.x-3.3
7.x-3.4
7.x-3.5
7.x-3.6
7.x-3.7
7.x-3.8
7.x-3.9
7.x-4.0
From that, the earliest tag that contains the stanford_courses_update_7300() update hook is 7.x-3.1






