4

我已经迁移了一个包含数百个分支和标签的大型 svn 存储库,将它们拆分为多个存储库,现在我正在检查这些存储库中是否有任何空*分支/标签,这些存储库应该在推送迁移之前删除。

有没有比去每个存储库检查每个分支更快的方法来找到它?


*就本问题而言,“空分支”或“空标签”是指指向不包含文件的提交的分支或标签。

4

2 回答 2

0

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

这是一个使用 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
于 2012-10-02T16:14:14.547 回答
0

我实际上最终为它做了这个脚本:

https://github.com/maxandersen/jbosstools-gitmigration/blob/master/deleteemptybranches.sh

    ## this will treat $1 as a repository and go through it and delete all branches and tags with empty content.

export GIT_DIR=$1/.git
export GIT_WORK_TREE=$1

echo Looking for empty branches in $1
git branch | while read BRANCH
do
 REALBRANCH=`echo "$BRANCH" | sed -e 's/\*//g'`
 NOFILES=`git ls-tree $REALBRANCH | wc -l | tr -d ' '`
# echo $NAME "$REALBRANCH" $NOFILES
 if [[ "$NOFILES" == "0" ]]
  then
     git branch -D $REALBRANCH 
  fi
done

git tag | while read BRANCH
do
 REALBRANCH=`echo "$BRANCH" | sed -e 's/\*//g'`
 NOFILES=`git ls-tree $REALBRANCH | wc -l | tr -d ' '`
# echo $NAME "$REALBRANCH" $NOFILES
 if [[ "$NOFILES" == "0" ]]
  then
     git tag -d $REALBRANCH 
  fi
done
于 2012-10-05T13:36:39.353 回答