Search code examples
gitdereference

When I have to use dereference in git and why?


We use tags for deployment of versions, when I execute command:

git ls-remote -t origin

I can see such picture

d5a0a2513d71dd94522039d9844daf8b8eed531f    refs/tags/live-0.0.1
43a6228d4bf5839aa934b541c35d19b897b35056    refs/tags/live-0.0.1^{}
a8662ef8bf021ea349dbf56970fd9f62f97093fb    refs/tags/live-0.0.2
b48d63ff5af0c9f488f99c2066824c8891ae394e    refs/tags/live-0.0.3

I can't find on my local rep this revision d5a0a2513d71dd94522039d9844daf8b8eed531f. Please, explain, when we have to use dereference? Maybe someone has an idea why it was done at my situation?(Maybe it was done by me, but I don't remember, maybe was testing something) And why I can't see this commit d5a0a2513d71dd94522039d9844daf8b8eed531f at local rep?


Solution

  • In git, SHA-1 hashes are used to identify all objects, not only commits. Object types include:

    • Trees
    • Blobs
    • Commits (revisions)
    • Tags

    Not all tags have their own SHA-ID. There are two types of tags:

    • Lightweight (without message, they are more like a branch that cannot be moved)
    • Annotated (created as a separate object, because tag message must be saved somewhere)

    Annotated tag contains message and commit SHA-ID, which is presented as a result of dereference (43a6228 in your case) and is identified itself as an object with ID (d5a0a25), which is required to retrieve tag message.

    So, you always need to dereference tags if you are looking for commit identifiers. Anyway, any tag name is always a valid commit identifier itself.