git: 列出悬挂标签
git: list dangling tags
上下文:
- 假设您有一些相当棘手的 CI/CD 工作流程,它依赖于 git 标签
- 功能分支已构建并生成一些短期 标记以表示产生可部署工件的提交
- 当功能分支被压缩合并时,通常它会被删除,但是标签,不出所料,仍然存在
- 经过几个月的开发,标签列表可以预见地变得多毛
因此,问题:
我将如何使用 git 命令行和可选的基本 bash 工具
- 列出给定标签可达的所有分支(对偶是
git tag -l --merged ${BRANCH_COMMITTISH}
,但我不需要给定分支的标签,而是给定标签的分支)
- 列出上面第 1 点的所有输出为空的标签(显然这可以用 for 循环 (给定 1 的任何终止实现),但也许有一些整洁的神奇的git单行)?
git branch --contains ${TAG}
https://git-scm.com/docs/git-branch#git-branch---containsltcommitgt.
git log --simplify-by-decoration --tags --not --branches --remotes --pretty=%d
--simplify-by-decoration
说只显示揭示祖先所需的最低限度(通常你将它与 --graph
一起使用)。 --tags --not --branches --remotes
说的是,好吧,它说的是:列出不在分支或远程历史中的标签历史,即无法从任何分支或远程跟踪分支访问的标签。 --pretty=%d
说只是显示参考。
只是为了说明我目前看到的所有解决方案:
~$ git init dangling_tags
Initialized empty Git repository in ~/dangling_tags/.git/
$ cd dangling_tags/
~/dangling_tags$ touch a.txt && git add a.txt && git commit -m a
[master (root-commit) f1b1070] a
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
~/dangling_tags$ git tag a
~/dangling_tags$ git checkout -b feature/add_some_tags
Switched to a new branch 'feature/add_some_tags'
~/dangling_tags$ touch b.txt && git add b.txt && git commit -m b
[feature/add_some_tags 1871cde] b
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
~/dangling_tags$ git tag b
~/dangling_tags$ touch c.txt && git add c.txt && git commit -m c
[feature/add_some_tags 26f6611] c
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 c.txt
~/dangling_tags$ git tag c
~/dangling_tags$ git checkout master
Switched to branch 'master'
~/dangling_tags$ git merge --squash feature/add_some_tags
Updating f1b1070..26f6611
Fast-forward
Squash commit -- not updating HEAD
b.txt | 0
c.txt | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
create mode 100644 c.txt
~/dangling_tags$ git commit
[master 99b33ae] Squashed commit of the following:
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
create mode 100644 c.txt
~/dangling_tags$ git branch --contains a
* master
~/dangling_tags$ git branch --contains b
feature/add_some_tags
~/dangling_tags$ git branch -D feature/add_some_tags
Deleted branch feature/add_some_tags (was 26f6611).
~/dangling_tags$ git tag
a
b
c
~/dangling_tags$ git branch --contains a
* master
~/dangling_tags$ git branch --contains b
~/dangling_tags$ for t in $(git tag); do if test "$(git branch --contains $t | wc -l)" == "0" ; then echo $t; fi done
b
c
~/dangling_tags$ git log --simplify-by-decoration --tags --not --branches --remotes --pretty=%d
(tag: c)
(tag: b)
上下文:
- 假设您有一些相当棘手的 CI/CD 工作流程,它依赖于 git 标签
- 功能分支已构建并生成一些短期 标记以表示产生可部署工件的提交
- 当功能分支被压缩合并时,通常它会被删除,但是标签,不出所料,仍然存在
- 经过几个月的开发,标签列表可以预见地变得多毛
因此,问题:
我将如何使用 git 命令行和可选的基本 bash 工具
- 列出给定标签可达的所有分支(对偶是
git tag -l --merged ${BRANCH_COMMITTISH}
,但我不需要给定分支的标签,而是给定标签的分支) - 列出上面第 1 点的所有输出为空的标签(显然这可以用 for 循环 (给定 1 的任何终止实现),但也许有一些整洁的神奇的git单行)?
git branch --contains ${TAG}
https://git-scm.com/docs/git-branch#git-branch---containsltcommitgt.
git log --simplify-by-decoration --tags --not --branches --remotes --pretty=%d
--simplify-by-decoration
说只显示揭示祖先所需的最低限度(通常你将它与 --graph
一起使用)。 --tags --not --branches --remotes
说的是,好吧,它说的是:列出不在分支或远程历史中的标签历史,即无法从任何分支或远程跟踪分支访问的标签。 --pretty=%d
说只是显示参考。
只是为了说明我目前看到的所有解决方案:
~$ git init dangling_tags
Initialized empty Git repository in ~/dangling_tags/.git/
$ cd dangling_tags/
~/dangling_tags$ touch a.txt && git add a.txt && git commit -m a
[master (root-commit) f1b1070] a
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
~/dangling_tags$ git tag a
~/dangling_tags$ git checkout -b feature/add_some_tags
Switched to a new branch 'feature/add_some_tags'
~/dangling_tags$ touch b.txt && git add b.txt && git commit -m b
[feature/add_some_tags 1871cde] b
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
~/dangling_tags$ git tag b
~/dangling_tags$ touch c.txt && git add c.txt && git commit -m c
[feature/add_some_tags 26f6611] c
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 c.txt
~/dangling_tags$ git tag c
~/dangling_tags$ git checkout master
Switched to branch 'master'
~/dangling_tags$ git merge --squash feature/add_some_tags
Updating f1b1070..26f6611
Fast-forward
Squash commit -- not updating HEAD
b.txt | 0
c.txt | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
create mode 100644 c.txt
~/dangling_tags$ git commit
[master 99b33ae] Squashed commit of the following:
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
create mode 100644 c.txt
~/dangling_tags$ git branch --contains a
* master
~/dangling_tags$ git branch --contains b
feature/add_some_tags
~/dangling_tags$ git branch -D feature/add_some_tags
Deleted branch feature/add_some_tags (was 26f6611).
~/dangling_tags$ git tag
a
b
c
~/dangling_tags$ git branch --contains a
* master
~/dangling_tags$ git branch --contains b
~/dangling_tags$ for t in $(git tag); do if test "$(git branch --contains $t | wc -l)" == "0" ; then echo $t; fi done
b
c
~/dangling_tags$ git log --simplify-by-decoration --tags --not --branches --remotes --pretty=%d
(tag: c)
(tag: b)