如何获取未合并到master中的分支列表,并通过最近的提交进行排序? [英] How do I get the list of branches not merged into master, ordered by most recent commit?

查看:130
本文介绍了如何获取未合并到master中的分支列表,并通过最近的提交进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们的buildbot,我想显示最近更新的活动(未发布)分支。假设我有一个 master 分支,以及从最旧到最新的commit:


  • branch1 (未合并到 master

  • branch2 (合并)

  • branch3 b $ b


我可以分别得到每个列表...例如获取所有未合并到 master 的分支:

  $ git分支-r  - 不合并的原产地/主产地
产地/分行1
产地/分行3

或者按照最近的提交次序(通过 https://coderwall.com/p/ndinba):

  $ git for-each-ref --sort = -committerdate --format ='%(committerdate:short )%(refname:short)'--count = 15 refs / remotes / origin / 
2013-03-22 origin / branch3
2013-03-22 origin / branch2
2013-03 -22 origin / master
2013-03-22 origin / branch1

所以我基本上想要第二个列表中减去 branch2 (带或不带 master )。希望是有道理的?

解决方案

b

  git for-each-ref --sort = -committerdate --format =%(committerdate:short)%(refname:short)--count = 15 $( git branch -r -no-merged origin / master | sed -e's##*#refs / remotes /#')

这会将 for-each-ref 限制为仅处理分支--no-merged reports ...



编辑:在实际测试后固定格式化 git branch 输出。 。


For our buildbot, I want to display the most recently-updated active (non-released) branches. Let's say I have a master branch, as well as the following, from oldest to newest commit:

  • branch1 (not merged into master)
  • branch2 (merged)
  • branch3 (not merged)

I am able to get each of these lists separately... e.g. to get all the branches not merged into master:

$ git branch -r --no-merged origin/master
origin/branch1
origin/branch3

Or to get the top fifteen branches, ordered by most recent commit (via https://coderwall.com/p/ndinba):

$ git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)' --count=15 refs/remotes/origin/
2013-03-22 origin/branch3
2013-03-22 origin/branch2
2013-03-22 origin/master
2013-03-22 origin/branch1

So I basically want that second list, minus branch2 (with or without master). Hope that makes sense?

解决方案

You could combine the two, like this:

git for-each-ref --sort=-committerdate --format="%(committerdate:short) %(refname:short)" --count=15 $(git branch -r --no-merged origin/master | sed -e 's#^ *#refs/remotes/#')

That will limit the for-each-ref to processing only the branches that branch --no-merged reports...

Edit: fixed formatting of git branch output after actually testing...

这篇关于如何获取未合并到master中的分支列表,并通过最近的提交进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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