> From: John Fisher <fishook2...@gmail.com>

> The SHA for the tag is not the SHA for the individual file. OK thats 
> obvious to experienced Git users, and the main point here. He wants to know 
> what the SHA for the file is just prior to the tag, (shown in Gitk BTW) . I 
> have shown him how to get the contents of a file by tag, but he wants the 
> SHA. ls-tree does not satisfy this as it associates a SHA with the file, a 
> SHA that is not listed in git log output.
> Why does ls-tree do this?
> How can he get a SHA listed in git log, that was created just before the 
> tag? ( without using dates which are FU'ed for extraneous reasons)

There is still some confusion here.

First, a tag is a name for a commit, not a bookmark that separates
"commits before the tag" from "commits after the tag".  The command
"git tag <tagname>" should print the commit id (which is a hash) for
the commit named by the tag.

"git ls-tree" lists the files that are contained in a commit.  It also
takes arguments to list only specific files within the commit.  So I
can say:

$ git ls-tree -r HEAD .bash_login
100644 blob 563ba2e54ebdf3977cf2ab744eaa4d457b58fc24    .bash_login

This lists the SHA of the version of .bash_login which is in the
commit HEAD.  Of course, I can replace HEAD with a tag name.

You ask "He wants to know what the SHA for the file is just prior to
the tag".  Do you mean, the SHA for the version of the file that
precedes the version in the tag?  There are two ways to answer that.

One is "What is the SHA for the file in the commit just before the
commit named by the tag?"  That is easy to answer, because
"<tagname>^" names the commit before the commit <tagname>.

I think he's asking "What is the SHA for the last different version of
the file before the tag?"

I think what will work is:

1) Find the first commit before the tag that has a different content
for the file:

$ git log -n 1 <tagname>^ -- <filename>
commit b3282e06e39e1ddaa44806eadbfac06a19fabe09

2) Find the SHA of the file as it is in that commit

$ git ls-tree <commit> -- <filename>
100644 blob <filehash>  <filename>

3) Get the contents of the file within that commit

$ git cat-file blob <filehash>


You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to