为什么git log --decorate每次提交不显示多个标记?
编辑:Charles Bailey提出了答案(至少在我的情况下)
基本上,我有一个标签指向另一个指向提交的标签.由于这个额外的间接层,标记未显示在日志中.我将不得不解决这个问题,通过修复我们的标记脚本来正确标记,或者通过一些shell脚本voodoo来递归跟踪标记.无论如何,我会留下这个问题仅供参考,万一有人想要它.(我是堆栈溢出的新手,但我认为这是正确的协议?)
背景故事:我们在工作中使用GIT进行源代码控制,我们的策略是在部署时始终标记提交.(它实际上是一个执行标记的脚本,然后在服务器上提取标记).由于它是一个具有单独的登台和生产服务器的Web应用程序,因此我们经常标记一个版本用于登台(用于测试或其他),然后标记相同的提交以进行生产.
所以我们经常在同一次提交中拥有多个标签.能够在文本日志中看到这一点会非常好,但它似乎不支持它.我目前正在解决这个问题,通过手动检查我正在寻找的标签,或通过启动gitk.虽然这两种解决方案都有效,但在我看来git log --decorate,默认情况下每次提交仅支持一个标记真的很奇怪.
我做了一些谷歌搜索,但没有找到太多.我错过了一些明显的东西吗
PS(我实际上使用自定义格式字符串%d,根据手册页和一些快速测试,它相当于--decorate)
Mar*_*les 75
git log --no-walk --tags --pretty="%h %d %s" --decorate=full
Run Code Online (Sandbox Code Playgroud)
此版本还将打印提交消息:
$ git log --no-walk --tags --pretty="%h %d %s" --decorate=full
3713f3f (tag: refs/tags/1.0.0, tag: refs/tags/0.6.0, refs/remotes/origin/master, refs/heads/master) SP-144/ISP-177: Updating the package.json with 0.6.0 version and the README.md.
00a3762 (tag: refs/tags/0.5.0) ISP-144/ISP-205: Update logger to save files with optional port number if defined/passed: Version 0.5.0
d8db998 (tag: refs/tags/0.4.2) ISP-141/ISP-184/ISP-187: Fixing the bug when loading the app with Gulp and Grunt for 0.4.2
3652484 (tag: refs/tags/0.4.1) ISP-141/ISP-184: Missing the package.json and README.md updates with the 0.4.1 version
c55eee7 (tag: refs/tags/0.4.0) ISP-141/ISP-184/ISP-187: Updating the README.md file with the latest 1.3.0 version.
6963d0b (tag: refs/tags/0.3.0) ISP-141/ISP-184: Add support for custom serializers: README update
4afdbbe (tag: refs/tags/0.2.0) ISP-141/ISP-143/ISP-144: Fixing a bug with the creation of the logs
e1513f1 (tag: refs/tags/0.1.0) ISP-141/ISP-143: Betterr refactoring of the Loggers, no dependencies, self-configuration for missing settings.
Run Code Online (Sandbox Code Playgroud)
Von*_*onC 16
关于标记标记(标记标记)的注释,这是问题的根源,正如Charles Bailey在评论中正确指出的那样:
确保你学习这个主题,因为重写签名标签并不容易:
git tag手册页严重建议不要git tag -f B更换标签名称" A"不要尝试重新创建带符号的标记git tag -f(请参阅下面的线程提取)
(这是关于一个角落的案例,但对于一般的标签非常有启发性,它来自另一个SO贡献者Jakub Nar?bski):
请注意,标签的名称(重量级标签,即标签对象)存储在两个地方:
- 在标签对象本身作为'标签'标题的内容(你可以在输出"
git show <tag>"和" "的输出中看到它git cat-file -p <tag>,其中<tag>是重量级标签,例如v1.6.3在git.git存储库中),- 并且也是标记引用的默认名称(在"
refs/tags/*"命名空间中引用)指向标记对象.
请注意,标记引用("refs/tags/*"命名空间中的适当引用)纯粹是本地事务; 例如,一个存储库在'refs/tags/v0.1.3'中有什么,其他可以在'refs/tags/sub/v0.1.3'.因此,当您创建签名标记'
A'时,您会遇到以下情况(假设它指向某个提交)
35805ce <--- 5b7b4ead <=== refs/tags/A
(commit) tag A
(tag)
Run Code Online (Sandbox Code Playgroud)
还请注意"
git tag -f A A"(注意没有选项强制它是带注释的标签)是一个noop - 它不会改变这种情况.如果你做"
git tag -f -s A A":注意你强制 ower写一个标签(所以git假定你知道你在做什么),并且-s/-a/-moptions之一用于强制带注释的标签(创建标签对象),你将获得以下情况
35805ce <--- 5b7b4ea <--- ada8ddc <=== refs/tags/A
(commit) tag A tag A
(tag) (tag)
Run Code Online (Sandbox Code Playgroud)
另请注意,"
git show A"会将整个链显示为非标记对象...
Gab*_*les 10
注:我只是解决问题的主题(强调):
显示所有标签
git log
...不是问题的具体细节。
git log(彩色!):我真的认为这是显示所有标签最有用和最漂亮的形式:
# standard, multi-line `git log` output
git log --no-walk --tags
# concise, one-line `git log` output
git log --no-walk --tags --oneline
Run Code Online (Sandbox Code Playgroud)
git log它显示了每个带有标签的提交的完整输出。非常便利!
试图理解 中的选项描述man git log,我认为这--tags会导致git log显示所有标签,即使该标签不在git log祖先树中的提交上,并告诉它仅--no-walk显示标签,而不是遍历树并显示所有非- 标记的提交也是如此。当然,添加该选项是为了获得每次提交一行的简洁输出(在本例中实际上是标记)。--oneline
如果您只想过滤掉与特定字符串搜索模式匹配的标签,请执行以下操作:
# multi-line output
git log --no-walk --tags=*some_string*
# one-line output
git log --no-walk --tags=*some_string* --oneline
Run Code Online (Sandbox Code Playgroud)
例子:
git log --no-walk --tags=*release/my_board*
Run Code Online (Sandbox Code Playgroud)
git log摘要(彩色!):如果您想查看更多信息。在每行标记提交输出中,执行此操作。注意:这是从Coderwall 的漂亮git lg别名修改而来的:
# fancy one-line output
git log --color --no-walk --tags --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
# vs regular one-line output
git log --no-walk --tags --oneline
Run Code Online (Sandbox Code Playgroud)
以下是Linux 内核官方“稳定”版本的一些示例输出:
linux_stable$ git log --color --no-walk --tags --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
650093916eb3 - (tag: v6.0.12, origin/linux-6.0.y) Linux 6.0.12 (5 days ago) <Greg Kroah-Hartman>
d9790301361c - (tag: v5.15.82, origin/linux-5.15.y) Linux 5.15.82 (5 days ago) <Greg Kroah-Hartman>
592346d5dc9b - (tag: v5.10.158, origin/linux-5.10.y) Linux 5.10.158 (5 days ago) <Greg Kroah-Hartman>
316cdfc48d4d - (tag: v5.4.226, origin/linux-5.4.y) Linux 5.4.226 (5 days ago) <Greg Kroah-Hartman>
e8fff2341723 - (tag: v4.19.268, origin/linux-4.19.y) Linux 4.19.268 (5 days ago) <Greg Kroah-Hartman>
65afe34ac33d - (tag: v4.14.301, origin/linux-4.14.y) Linux 4.14.301 (5 days ago) <Greg Kroah-Hartman>
b6097015eea4 - (tag: v4.9.335, origin/linux-4.9.y) Linux 4.9.335 (5 days ago) <Greg Kroah-Hartman>
76dcd734eca2 - (tag: v6.1-rc8) Linux 6.1-rc8 (8 days ago) <Linus Torvalds>
31e4bdd2c25b - (tag: v6.0.11) Linux 6.0.11 (10 days ago) <Greg Kroah-Hartman>
e4a7232c917c - (tag: v5.15.81) Linux 5.15.81 (10 days ago) <Greg Kroah-Hartman>
Run Code Online (Sandbox Code Playgroud)
linux_stable$ git log --no-walk --tags --oneline
650093916eb3 (tag: v6.0.12, origin/linux-6.0.y) Linux 6.0.12
d9790301361c (tag: v5.15.82, origin/linux-5.15.y) Linux 5.15.82
592346d5dc9b (tag: v5.10.158, origin/linux-5.10.y) Linux 5.10.158
316cdfc48d4d (tag: v5.4.226, origin/linux-5.4.y) Linux 5.4.226
e8fff2341723 (tag: v4.19.268, origin/linux-4.19.y) Linux 4.19.268
65afe34ac33d (tag: v4.14.301, origin/linux-4.14.y) Linux 4.14.301
b6097015eea4 (tag: v4.9.335, origin/linux-4.9.y) Linux 4.9.335
76dcd734eca2 (tag: v6.1-rc8) Linux 6.1-rc8
31e4bdd2c25b (tag: v6.0.11) Linux 6.0.11
e4a7232c917c (tag: v5.15.81) Linux 5.15.81
Run Code Online (Sandbox Code Playgroud)
当然,您仍然可以使用--tags=*some_string*表单来过滤您想要的某些标签:
git log --color --no-walk --tags=*some_string* --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Run Code Online (Sandbox Code Playgroud)
例子:
git log --color --no-walk --tags=*release/my_board* --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Run Code Online (Sandbox Code Playgroud)
git lg别名man git log,以及我自己的个人实验注意:来自brian m的提交5e1361c .carlson(bk2204)(适用于git 1.9/2.0 Q1 2014)处理带有标签的日志装饰的特殊情况:
log:使用链式标签正确处理装饰
git log当标记对象引用另一个不再是ref的标记对象时,例如删除第二个标记时,没有正确处理装饰.
提交将无法正确修饰,因为parse_object未在第二个标记上调用,因此其标记字段尚未填写,导致没有任何标记与相关提交相关联.
parse_object如果不存在则调用填写此字段,以便可以取消引用标记链并且可以正确地修饰提交.
包括测试以防止将来的回归.
例:
git tag -a tag1 -m tag1 &&
git tag -a tag2 -m tag2 tag1 &&
git tag -d tag1 &&
git commit --amend -m shorter &&
git log --no-walk --tags --pretty="%H %d" --decorate=full
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
97289 次 |
| 最近记录: |