Post

Git清理脚本

Git清理脚本

Git一些常用的shell脚本记录

删除分支

找出所有已经合并的本地分支

1
for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r >> branches

检查一下 没问题就可以准备删除

1
cat branches |awk '{print($8)}' | xargs git branch -D

找出所有已经合并的本地分支

1
2
3
for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r
cat months |awk '{print($10)}' | sed "s/origin\///" | xargs git push origin --delete
cat months3 |awk '{print($8)}'| sed "s/origin\///" |xargs git push origin --delete

时间判断

找出大于4周的数据

1
2
3
4
cat branchs|awk '$5=="weeks" && $4>4'
git branch -r |grep  '' -c
for branch in `git branch -r  | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r
for branch in `git tag | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r
This post is licensed under CC BY 4.0 by the author.