如何在git中找到空的分支和标签 [英] How to find empty branches and tags in git

查看:95
本文介绍了如何在git中找到空的分支和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经迁移了一个大型的svn存储库,其中包含数百个分支和标签,将它们拆分为多个存储库,现在我要检查在这些存储库中是否有任何空*分支/标记应删除,然后再推送实时迁移.

I've migrated a big svn repository with hundreds of branches and tags, split them into multiple repositories and now i'm looking to check if there are any empty* branches/tags in these repositories that should be deleted before pushing the migration live.

有比找到每个存储库并检出每个分支更快的方法吗?

Is there a faster way to find this than having to go to every repository and checkout every branch ?

*就此问题而言,空分支"或空标记"是指指向不包含任何文件的提交的分支或标记.

*For the purpose of this question, "empty branch" or "empty tag" means a branch or tag that points to a commit that contains no files.

推荐答案

使用您选择的编程语言为每个分支和标签运行git ls-tree <branch/tag> | wc -l,并检查0.您可以使用git branch获取分支列表,并使用git tag获取标签列表.

Run git ls-tree <branch/tag> | wc -l for every branch and tag using the programming language of you choice and check for 0. You get a list of branches with git branch and a list of tags with git tag.

这是一个使用bash的分支的简单示例:

Here is a simple example for branches using bash:

#!/bin/bash

for branch in $(git branch | cut -c 3-)
do
  if [ $(git ls-tree $branch | wc -m) -eq 0 ]
  then
    echo "branch $branch is empty"
  fi
done

这篇关于如何在git中找到空的分支和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆