显示git log中的所有标签 [英] show all tags in git log
问题描述
为什么 git log --decorate
每个提交不会显示多个标记?
编辑:Charles Bailey提出了答案(至少在我的情况中)
基本上,我有一个标签指向另一个标签,指向承诺。由于这种额外的间接层,标签没有出现在日志中。我必须解决这个问题,通过修正我们的标记脚本来正确标记,或者通过一些shell脚本巫术来递归跟踪标记。无论如何,我会留下这个问题仅供参考,以防有人需要。 (我是堆栈溢出的新手,但我认为这是正确的协议?)
...原始问题如下...
Backstory:我们在工作中使用GIT进行源代码控制,并且我们有一个在部署时总是标记提交的策略。 (它实际上是一个脚本,它执行标签,然后将标签拉到服务器上)。由于它是一个具有独立登台和生产服务器的Web应用程序,因此我们通常会为暂存(用于测试或其他)标记一个发布,然后稍后将相同的提交标记为生产。
所以实际上我们在同一个提交中有多个标签。能够在文本日志中看到这一点是非常好的,但似乎并不支持它。我目前正在通过手动检查我正在查找的标签或通过启动 gitk
来解决此问题。虽然这两个解决方案都能正常工作,但在我看来, git log --decorate
在每次提交时默认只支持一个标记。
我做了一些Google搜索,但没有发现太多。我是否缺少明显的东西?
P.S。 (根据手册页和一些快速测试,我实际上使用了一个自定义格式字符串(%d
),它相当于 - 装饰
关于标记(标记标记)的标记您的问题,正如 Charles Bailey 在评论中正确指出的那样:
请确保您学习此主题,因为覆盖已签署的代码是并非如此简单:如果您已经推送了一个标签,那么
-
git tag
手册页严格建议不要使用简单code> git tag -f B 替换标记名称A
-
不要尝试使用
git tag -f
重新创建签名标记(请参阅线程ext )(这是关于一个角落的情况,但对标签总体而言非常有启发性,它来自另一个SO贡献者
$ b$ b
- $ b
请注意,标记(重量级标记,即标记对象)
的名称存储在两个地方:
- 在标签对象本身作为'标签'标头的内容(你可以在
git show< tag>
>的输出中看到它,git cat-file -p< tag>
,其中< tag>
是重量级标签,例如v1.6.3
位于git.git
存储库), - 标签引用的默认名称(在<
refs / tags / * >命名空间中引用)指向标签对象。
请注意,标签参考(在<refs / tags / * >命名空间中的适当引用)纯粹是 local ; ' refs / tags / v0.1.3
',其他可以在'refs / tags / sub / v0.1.3
'例如。
所以当你创建签名标记'
A
',你有以下情况(假设它指向某个提交)
35805ce< --- 5b7b4ead< === refs / tags / A
(commit)tag A
(tag)
请注意
git tag -f AA
(注意没有选项强制它是一个注释标记)是一个noop - 它不会改变这种情况。
如果你这样做
git tag -f - s AA
:注意,你强制写一个标签(所以git假定你知道你在做什么),并且-s之一
/-a
/-m
选项用于强制注释标签(创建标签对象),你会得到以下情况
35805ce< --- 5b7b4ea< --- ada8ddc< == =标签A
(标签)(标签)
还要注意,
git show A
会显示整个链向下的非标记对象...
Why does
git log --decorate
not display more than one tag per commit?EDIT: Charles Bailey has come up with the answer (at least in my case)
Essentially, I had one tag that pointed to another tag that pointed to the commit. Because of this extra layer of indirection, the tag wasn't showing up in the log. I'll have to fix this, wither by fixing our tagging script to tag correctly, or by some shell script voodoo to recursively follow tags. Anyway, I'll leave this question up just for reference in case anyone wants it. (I'm new to stack overflow, but I assume that is the correct protocol?)... Original question follows ...
Backstory: We use GIT at work for source control, and we have a policy of always tagging a commit when we deploy. (It's actually a script that does tags, and then pulls the tag on the server). Since it's a web application with separate staging and production servers, we often tag a release for staging (for testing or whatever), and then later tag the same commit for production.
So it's actually very often that we have multiple tags on the same commit. It would be very nice to be able to see this in the text log, but it doesn't seem to support it. I'm currently working around the issue by manually checking the tag I'm looking for, or by firing up
gitk
. While both of these solutions work, it seems to me that it's really weird forgit log --decorate
to only support one tag per commit by default.I did some googling around, but didn't find much. Am I missing something obvious?
P.S. (I actually use a custom format string with
%d
, according to the man pages and some quick tests, it's equivalent to--decorate
)解决方案Note about tag of tag (tagging a tag), which is at the origin of your issue, as Charles Bailey correctly pointed out in the comment:
Make sure you study this thread, as overriding a signed tag is not as easy:
- if you already pushed a tag, the
git tag
man page seriously advised against a simplegit tag -f B
to replace a tag name "A
" don't try to recreate a signed tag with
git tag -f
(see the thread extract below)(it is about a corner case, but quite instructive about tags in general, and it comes from another SO contributor Jakub Narębski):
Please note that the name of tag (heavyweight tag, i.e. tag object) is stored in two places:
- in the tag object itself as a contents of 'tag' header (you can see it in output of "
git show <tag>
" and also in output of "git cat-file -p <tag>
", where<tag>
is heavyweight tag, e.g.v1.6.3
ingit.git
repository), - and also is default name of tag reference (reference in "
refs/tags/*
" namespace) pointing to a tag object.
Note that the tag reference (appropriate reference in the "refs/tags/*
" namespace) is purely local matter; what one repository has in 'refs/tags/v0.1.3
', other can have in 'refs/tags/sub/v0.1.3
' for example.
So when you create signed tag '
A
', you have the following situation (assuming that it points at some commit)35805ce <--- 5b7b4ead <=== refs/tags/A (commit) tag A (tag)
Please also note that "
git tag -f A A
" (notice the absence of options forcing it to be an annotated tag) is a noop - it doesn't change the situation.If you do "
git tag -f -s A A
": note that you force owerwriting a tag (so git assumes that you know what you are doing), and that one of-s
/-a
/-m
options is used to force annotated tag (creation of tag object), you will get the following situation35805ce <--- 5b7b4ea <--- ada8ddc <=== refs/tags/A (commit) tag A tag A (tag) (tag)
Note also that "
git show A
" would show the whole chain down to the non-tag object...这篇关于显示git log中的所有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- if you already pushed a tag, the
- 在标签对象本身作为'标签'标头的内容(你可以在