删除所有超过X天/周的分支 [英] Delete all branches that are more than X days/weeks old
问题描述
我发现下面的脚本按日期列出了分支。如何过滤这个以排除较新的分支并将结果提供给Git delete命令?
$ b $ $ $ $ $ $ $ $ $ $ $ $ $(git分支中的$ | sed / \ * / d);做
echo$(git log -1 --pretty = format:%ct$ k)$ k
done | sort -r | awk'{print $ 2}'
code> - 既然和 - 之前
?
例如,这将删除所有未收到任何提交一周的分支:
for $ in $(git branch | sed / \ * / d);如果[-n$(git log -1 --since ='1周前'-s $ k)]执行
;然后
git分支-D $ k
fi
完成
如果您想删除超过一周的所有分行,请在之前使用:
$(git branch | sed / \ * / d)中的$ 做
if [-n$(git log -1 --before ='1 week ago'-s $ k)];然后
git分支-D $ k
fi
完成
不过要注意的是,这也会删除那些没有合并到master或任何签出分支的分支。
I found the below script that lists the branches by date. How do I filter this to exclude newer branches and feed the results into the Git delete command?
for k in $(git branch | sed /\*/d); do
echo "$(git log -1 --pretty=format:"%ct" $k) $k"
done | sort -r | awk '{print $2}'
How about using --since
and --before
?
For example, this will delete all branches that have not received any commits for a week:
for k in $(git branch | sed /\*/d); do
if [ -n "$(git log -1 --since='1 week ago' -s $k)" ]; then
git branch -D $k
fi
done
If you want to delete all branches that are more than a week old, use --before
:
for k in $(git branch | sed /\*/d); do
if [ -n "$(git log -1 --before='1 week ago' -s $k)" ]; then
git branch -D $k
fi
done
Be warned though that this will also delete branches that where not merged into master or whatever the checked out branch is.
这篇关于删除所有超过X天/周的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!