Is it possible to fix a detached head with a tag? In other words, is it possible to prevent garbage collector deleting commits in a detached head with a tag at the last commit?
Every other post that I've found talk about creating a branch in the detached head to prevent losing commits that have been created in this state before leaving to another branch.
As I understand, the major difference between a tag and a branch is the branch moving with the head compared to the tag which stays at the exact same position where it was created.
In my scenario, I've checked out with an SHA-1 and then done a couple of commits from this point. Before leaving, I want to put a bookmark and I think in term of semantic, a tag would be better than a branch to go back later.
I don't have any problem creating a branch at this point instead of a tag if this is the only thing that I can do but I'm wondering about the behavior of git internally with tags and branches with relation with a detached head.
Also, conceptually, if someone does not agree with me about creating a tag instead of a branch, in this case, an explanation would be appreciated.
答案 0 :(得分:2)
将标记保存为将来的某些提交并不是错误的。但是,有一些缺点:
git fetch
或push
带有一些选项会将所有标记复制到目标端,而不进行任何映射。因此,任何私有临时标记都可能以公共名称空间结束。总的来说,我会说标签更多的是作为公共永久里程碑,例如发布。
还有更多选择需要考虑:
tags
或branches
。这是例如bisect对中间标记的作用答案 1 :(得分:1)
Yes, a tag will prevent garbage collection the same way a branch does. Only unreachable commits are eligible for garbage collection, and git checks every ref to check if the commit is reachable.