tags:

views:

139

answers:

3

I need to to tell which revision/SHA1 of a file was associated with one or more tags. In CVS it is possible to get an output similar to to this:

File: abc.txt
Rev: 1.0
Tags: R1_0, R1_1

Rev: 1.1
Tags: R1_2

How do you get a tag history for a file with git?

Edit: I frequently use this function to tell which revision of a file is in production. I know which version (tag) of software is in production. Based upon this I would like to know which revision of a given file was tagged (and also which previous tags were associated to this file revision).

In my example above:
R1_1 will be in production. Querying abc.txt, I can tell that rev1.0 for abc.txt was used for both R1_0 and R1_1. (Thus unlikely that a new bug in R1_1 was caused by abc.txt because it still the same file as R1_0)

A: 

What are you trying to accomplish? The SHA1 identifies the state of the entire repo at that point in time.

Hank Gay
Updated my question to describe my intent better.
Philip Fourie
+3  A: 

I think you're trying to be too specific in literally translating concepts from one revision control system to another. I'd ask, "how has abc.txt changed since R1_1?"

git log R1_1.. -- abc.txt

Now you know two things -- that it's changed, and how. Toss in a -p if you want to see the changes, too.

Less Helpful, but What You Asked For:

To do exactly what you're asking for (which I think is less useful), and assuming you're tagging properly:

git describe `git log --pretty=format:%H -n 1 abc.txt`

That shows you closest thing to a tag name for the last commit that changed the file.

Dustin
+1  A: 

In git tags are always associated with state of whole project, not with the version of a single file. You can easily get however list of all files that changed between versions with "git diff --name-only R1_0 R1_1" (or more descriptive "git diff --stat --summary R1_0 R1_1". You can get last commit that touched a file with "git log -1 <file>".

But if you want to find a bug, it is much better in my opinion to use git-bisect command to find which revision introduced bug. You would know not only which file has a bug, but which part of file introduced it (what change creared it).

Jakub Narębski