Say I do the following:
X
t
(to branch X
)X
What happen to tag t
? is it just floating there? is it considered as garbage?
Should I remove all tags pointing at branch before removing the branch itself?
From Git Basics - Tagging:
Git uses two main types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesn’t change – it’s just a pointer to a specific commit.
The tag and commit would still exist if the branch is deleted. A branch is simply a way to track a collection of commits.
By omitting the source ref (the part before the colon), you push 'nothing' to the destination, deleting the ref on the remote end. It is also interesting to know that git tag -d `git tag` will delete all local tags.
The most common style is to use annotated tags for permanent tags, things which you expect to push and you expect other people to look at. Lightweight tags are then used for temporary tags, things which you will not push and which you do not want other people to see.
Sharing tags is similar to pushing branches. By default, git push will not push tags. Tags have to be explicitly passed to git push .
What happen to tag t?
Let's say you created branch x
from a commit E
and then tagged that commit with tag t
. E.g.
x (branch) | V A-----B------C------D------E ^ | t (tag)
If you remove branch x
nothing happens to tag t
.
git branch -D x
The tag still points to commit E
.
A-----B------C------D------E ^ | t (tag)
is it considered as garbage?
No, because the commit is still referenced by tag t
.
What if the commit is removed?
You do not remove commits. You remove pointers to commits and if commits are no longer referenced git will garbage collect them some day (depending on your configuration).
See git gc
Even if you removed all ordinary refs, like branches and tags, the commits will still be referenced in the reflog for some time and you can access them, e.g. re-create a branch, tag them or cherry-pick and so on.
You can see the reflog using git reflog
. Also take a look at gc.reflogExpireUnreachable
and gc.reflogExpire
EDIT
If somehow git's object database is corrupted. Either a file from .git/objects
was deleted (e.g. you accidentially deleted it using your file explorer or a command-line command) or a ref points to a non-existent git object (like a commit, tree or blob object), you will get errors if git tries to access these objects.
Here is a list of errors that might occur when git tries to access an object that does not exist or if a non-existent object is referenced.
commit
fatal: Could not parse object '<ref-name>'.
example:
fatal: Could not parse object 'master'.
tree
fatal: unable to read tree <tree-sha1>
example:
fatal: unable to read tree 13a3e0908e4f6fc7526056377673a5987e753fc8
blob
error: unable to read sha1 file of <blob-name> (<blob-sha1>)
example:
error: unable to read sha1 file of test.txt (e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)
Take a look at Git Internals for a deeper understanding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With