On Sat, Mar 17, 2018 at 01:17:12PM +0100, Michal Novotny wrote:

> let's say I have made an annotated tag on a certain treeish:
> 
> $ git tag -a -m msg tagname HEAD:
> 
> Now, I can try to see the content of the tag:
> 
> $ git tag -v tagname
> object 42a1c36553a50ceae2f75ffc4b1446c6c393eae7
> type tree
> tag tagname
> tagger clime <cl...@redhat.com> 1521288727 +0100
> 
> msg
> error: no signature found
> 
> 
> Can I use that object ID 42a1c36553a50ceae2f75ffc4b1446c6c393eae7 to
> get back to a particular commit from which the tag was created? The
> reason is that I would eventually like to checkout that commit.

In general, you can't, and that's because there can be any number of
commits referencing that tree. A typical case is a tree object
representing a subdirectory of your project which changes rarily, if
ever - in this case, each commit which includes the same state of this
subdirectory will refer the same tree object.

Another point to consider is that the commit itself only refers to a
single tree object -- that one which records the state of the top-level
project directory, and it usually refers to other three objects which
may, in turn, refer to others and so on - all the way down.

So actually a generic approach to what you need is a full scan of all
the commits in the repository with recursive traversing of the hierarchy
of trees of each of them (via `git ls-tree`) and looking for the SHA-1
name of the reference tree object.  As you can see, this is not going to
be fast on repos of realistic size.

Reply via email to