批量删除已重新建立基础并合并的本地分支 [英] Mass deleting local branches that has been rebased and merged

查看:105
本文介绍了批量删除已重新建立基础并合并的本地分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的团队中,我们保留主分支和开发分支的仅快进合并策略,以防止合并提交地狱:

in our team we keep the fast-forward only merge policy for master and development branches in order to prevent merge commit hell:

一旦合并(或重新设置基础然后合并),我就不会删除我的主题分支,因此最终会有很多这样的问题.我可以删除一些内容:

I do not delete my topic branches once they are merged (or rebased and then merged), so I end up with tons of these. I can delete some:

git branch --merged

这只会向我显示那些在合并之前没有重新设置基准的对象.其中有一些,我能够清理它们.

This will only show me those which hasn't been rebased prior merge. And there are some of these, I am able to clean them up.

我正在寻找一些策略,脚本或提示,以应对重新设置的策略.必须有一个脚本,可以以循环或其他方式从master的topic分支中查找所有提交.请分享;-)

I am looking for some strategy, script or hint how to deal with the rebased ones. There must be a script that finds all the commits from the topic branch in the master in a loop or something. Please share ;-)

谢谢

推荐答案

您有一个脚本这样做的方式是:

  • 获取每个分支的最后一次提交
  • 检查提交是master历史的一部分

这将删除已合并到master的重新建立基础的分支.

That would delete rebased branches which have been merged to master.

last_commit_msg="$(git log --oneline --format=%f -1 $branch)"
if [[ "$(git log --oneline --format=%f | grep $last_commit_msg | wc -l)" -eq 1 ]]; then

这篇关于批量删除已重新建立基础并合并的本地分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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