Does a git tag point to a specific sha1, a specific commit on a specific branch, or something else?
This question is extremely similar to What happen to Git tags pointing to a removed commit, but I am unable to find the answer I am looking for there.
Let's use the following example:
C (Branch, cut with same commit history)
|
A-----B-----C (Main)
I'm trying to help myself answer the following questions:
If I tag commit C on Main before cutting Branch, does my tag apply to Main and/or Branch?
If I tag commit C on Main after cutting Branch, does my tag apply to both Main and/or Branch?
If I tag commit C on Branch after cutting Branch, does my tag apply to both Main and/or Branch?
What happens if there is a different commit history? For example, does anything change with the following:
C-----D-----E (tag on E in either the main branch or this branch)
|
A-----B-----C-----E
edit: looks like #4 is impossible because a commit cannot have the same hash if the parent is different
An ordinary tag is just a name for a specific Git object, which is usually a commit but can be a tree, a blob, or anything else with a hash.
An annotated tag is itself a distinct object that contains a reference to another object.
Regarding your questions:
It applies to C. Main
and Branch
are currently just two other names for the same commit. But committing to either branch does not affect what the tag will refer to; it will remain a name of the commit C.
Neither. The tag refers to C, not any of the branch heads that may also refer to C.
Neither. It refers to C.
The branch history doesn't really make sense. Your two Cs are distinct commits, as are your two Es. The tag would refer to exactly one of the two Es.
In short: tags are usually independent of branches.