如何删除所有已经“压缩并合并"的git分支?通过GitHub? [英] How can I delete all git branches which have been "Squash and Merge" via GitHub?

查看:55
本文介绍了如何删除所有已经“压缩并合并"的git分支?通过GitHub?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从GitHub引入 Squash and Merge 之后,我所有的好孩子合并拉取请求时,工作场所正在使用它.有没有办法清理"Squash and Merge"分支?

Ever since GitHub introduced Squash and Merge, all the cool kids at my workplace are using it when merging pull requests. Is there a way to cleanup "Squash and Merge" branches?

来自的以下命令删除所有已合并的git分支吗?不适用于"Squash and Merge":

The following command from How can I delete all git branches which have been merged? does not work for "Squash and Merge":

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

推荐答案

下面是一个脚本,该脚本将删除所有已合并为master的壁球分支.

Here's a script that will delete all local branches that have been squash merged into master:

git checkout -q master && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base master $branch) && [[ $(git cherry master $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done

如果要进行空运行,则可以运行以下命令:

If you want to run a dry run, you can instead run this:

git checkout -q master && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base master $branch) && [[ $(git cherry master $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && echo "$branch is merged into master and can be deleted"; done

然后您可以像这样设置别名:

You can then setup an alias like this:

alias gprunesquashmerged='git checkout -q master && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base master $branch) && [[ $(git cherry master $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done'

来源:

https://github.com/not-an-aardvark/git-删除压缩

这篇关于如何删除所有已经“压缩并合并"的git分支?通过GitHub?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆