Git: Show all of the various changes to a single line in a specified file over the entire git history

git

I've looked around, and am not sure if this is possible, but here goes:

I have a (javascript) file (say /lib/client.js) in which I have a unique identifier assigned to a variable, like so:
var identifier = "SOME_IDENTIFIER";

You can think of the identifier like a version number: Periodically, we'll change this variable to a new identifier.

What I'd like to do is find all of the unique identifiers we've ever used. How can I do this with git?

I imagine there might be a way to search through the git history, and print the line matching "var identifier =". I could de-dupe this list manually.

Anyway, I'd appreciate any insight here. Thanks.

Best Solution

Since git 1.8.4, there is a more direct way to answer your question.

Assuming that line 110 is the line saying var identifier = "SOME_IDENTIFIER";, then do this:

git log -L110,110:/lib/client.js

This will return every commit which touched that line of code.

[Git Documentation (see the "-L" command line paramenter)]