如何查找不在任何分支中的 Git 提交?

问题描述 投票:0回答:1

在我当前工作的存储库中,有一堆提交,其分支在没有合并的情况下被删除,但由于创建了指向提交的标签,因此这些提交将永远存在。

如何列出这些标签以将其删除?

谢谢你。

git repository commit
1个回答
0
投票

您可以在 Linux 上使用以下 bash 脚本 来查找不在任何分支中的提交,您可以在 Git 存储库中运行脚本。

此脚本将迭代不在任何分支中的所有提交,并删除与它们关联的标签。

#!/bin/bash

for commit_id in $(git log --all --not --branches=* --format="%H")
do
    for tag in $(git tag --contains $commit_id)
    do
        echo "Removing tag: $tag"
        git tag -d $tag
    done
done
© www.soinside.com 2019 - 2024. All rights reserved.