我正在尝试编写一个 bash 脚本来清理一些东西,其中一部分是对我拥有的所有分支进行排序。我正在尝试获取过去 2 个月内未提交的存储库中的分支名称列表。我将把这个列表存储在一个变量中,并浏览每一个我可以删除的列表。
到目前为止我一直在做以下事情:
git clone -q --depth 1 --bare --no-single-branch **REMOTE_URL** tmp/tmp-location
cd tmp/tmp-location
git branch --format='%(color:bold green) %(refname:short) %(color:white) %(committerdate)' --sort=-committerdate
或者我也做了以下事情:
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - (%(color:green)%(committerdate:relative)%(color:reset))'
这非常适合列出所有分支并按提交者日期排序,但我不知道如何获取提交者日期早于 2 个月的分支列表。
甚至更好 是否可以检查特定分支名称的最后提交日期,而不仅仅是像上述解决方案中的所有分支?
我会如何列出每个本地分支一个月以来的提交:
#!/usr/bin/env bash
git checkout master
for branch in $(git branch | tr -d '\*'); do
[[ $branch == master ]] && continue
git checkout $branch
echo $branch
git log --since="$(LC_ALL=C date -d '1 month ago')" master.. | grep -c '^commit '
done