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.
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
.
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