Reputation: 49714
Here's what I did...
git checkout -b test-branch
### add a line of text to a .md file, then...
git commit -am 'a commit that will never be pushed'
git tag my-tag
git push --tags
### NOTE: I ONLY pushed the tag (not the branch)
So...
I have not pushed the commit
I have not pushed the branch the commit is on
But...
When I view the tag in github
Then click on the associated SHA I see the actual (un-pushed) commit
I thought a Tag was only a pointer to a SHA.
How is it I am seeing the contents of an un-pushed commit? And what is going on?
Upvotes: 7
Views: 5971
Reputation: 534950
Git traffics in commits. A commit is a thing. Everything else is just information about those commits.
A tag refers to a commit. Saying checkout a tag checks out a commit. Saying push a tag pushes a commit.
You cannot push a tag without pushing the commit that it points to (along with everything reachable from it that the remote may lack). A tag pointing to a nonexistent commit would be a broken repo!
(Of course, typically when we push tags, the remote already has the commits referred to, so no actual transfer of commits takes place. But in formulating this edge case, you arranged things so that the remote did not already have this commit.)
It's the same as a branch. A branch refers to a commit. Checking out a branch checks out a commit. Pushing a branch pushes a commit. Pushing a branch doesn't transfer just a name, it transfers commits.
Upvotes: 3
Reputation: 239260
I have not pushed the commit
Yes you have, whether you know it or not, otherwise the remote would reject the tag.
You never "push the commits" manually, you push them implicitly while pushing a branch or tag that references the commits. Tags and branches are more or less identical. Commits are not "on branches", anymore than they are "on tags". Branches and tags are pointers to commits, and when you push one of either type, the commits it references must also be pushed.
The same way you don't have to ask Git to specifically download all the commits when you check out a branch. Git does this for you.
I thought a Tag was only a pointer to a SHA (not a container for commits...)
Yes, exactly the same as a branch. They're both just pointers to commit IDs.
Upvotes: 11