指向删除的提交的Git标签会发生什么 [英] What happen to Git tags pointing to a removed commit
问题描述
说我要执行以下操作:
- 创建分支
X
- 创建标签
t
(以分支X
) - 推
- 删除分支
X
标记t
会发生什么?它只是漂浮在那儿吗?是垃圾吗?
在删除分支本身之前,是否应该删除所有指向该分支的标签?
参考
来自 Git基础知识-标记:
Git使用两种主要类型的标签:轻量级标签和带注释的标签.一种 轻量级标签非常像不变的分支– 只是指向特定提交的指针.
标记t会怎样?
假设您从提交E
创建了分支x
,然后使用标签t
标记了该提交.例如
x (branch)
|
V
A-----B------C------D------E
^
|
t (tag)
如果删除分支x
,则标记t
没有任何反应.
git branch -D x
标记仍指向提交E
.
A-----B------C------D------E
^
|
t (tag)
是否被视为垃圾?
否,因为该提交仍被标记t
引用.
如果删除提交该怎么办?
您不删除提交.您删除指向提交的指针,如果不再引用提交,则git将有一天垃圾回收它们(取决于您的配置).
请参见 git gc
>
即使您删除了所有普通的ref,例如分支和标签,提交仍会在reflog中被引用一段时间,您可以访问它们,例如重新创建分支,对其进行标记或选择樱桃等.
您可以使用 git reflog
来查看reflog.还要看看gc.reflogExpireUnreachable
和gc.reflogExpire
Say I do the following:
- Create branch
X
- Create Tag
t
(to branchX
) - Push
- Remove branch
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?
Reference
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.
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
这篇关于指向删除的提交的Git标签会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!