2013-03-22 40 views
8

对于我们的buildbot,我想显示最近更新的活动(未发布)分支。比方说,我有一个master分支,以及下面,从最旧到最新承诺:如何获取未合并到master中的分支列表,按最近的提交顺序排列?

  • branch1(未合并到master
  • branch2(合并)
  • branch3(未合并)

我能够分别获得这些列表中的每一个...例如让所有的分支没有被合并到master

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

或获得前十五名的分支,由最近下令提交(通过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)。希望这是有道理的?

+0

与GIT 2.7(Q4 2015),'GIT中的for-each-REF --no-合并的主参/头/'将成为可能!请参阅[我的答案](http:// stackoverflow。com/a/32988584/6309) – VonC 2015-10-07 09:25:58

回答

11

你可以将二者结合起来,就像这样:

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加工只有分支是branch --no-merged报告...

编辑:实际测试后git branch输出的固定格式...

+0

hmm,'error:unknown switch \'>'' – 2013-03-22 19:33:52

+0

不确定消息来自哪里 - 命令行不包含'>'...在任何情况下,我都会在有机会后更新命令要真正尝试它... – twalberg 2013-03-22 19:41:40

+0

相同的错误: -/bash和zsh。 – 2013-03-22 19:45:17

1

难道你只是grep出branch2?

基本上是这样的:

for branch in `git branch -r --no-merged origin/master`; do git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)' --count=15 refs/remotes/origin/ | grep $branch; done; 

,对我的工作给予你的样品输出。

+0

'grep:正则表达式太大'哈哈 – 2013-03-22 19:34:57

+0

您谈论过多少个未装配的分支? – spitzanator 2013-03-22 19:40:10

+0

74,哈哈。需要清理一些这些。 – 2013-03-22 19:44:09

0

随着git 2.7(Q4 2015),git for-each-ref,将支持--no-merged选项

git for-each-ref --no-merged master refs/heads/ 

随着DOC:

--no-merged [<object>]: 

Only list refs whose tips are not reachable from the specified commit (HEAD if not specified).


commit 4a71109commit ee2bd06commit f266c91commit 9d306b5commit 7c32834commit 35257aacommit 5afcb90,...,commit b2172fd(2015年7月7日),并commit af83baf (2015年7月9日)Karthik Nayak (KarthikNayak)
(在commit 9958dd8Junio C Hamano -- gitster --合并,2015年10月5日)

Some features from " git tag -l " and " git branch -l " have been made available to " git for-each-ref " so that eventually the unified implementation can be shared across all three, in a follow-up series or two.

* kn/for-each-tag-branch: 
    for-each-ref: add '--contains' option 
    ref-filter: implement '--contains' option 
    parse-options.h: add macros for '--contains' option 
    parse-option: rename parse_opt_with_commit() 
    for-each-ref: add '--merged' and '--no-merged' options 
    ref-filter: implement '--merged' and '--no-merged' options 
    ref-filter: add parse_opt_merge_filter() 
    for-each-ref: add '--points-at' option 
    ref-filter: implement '--points-at' option 
相关问题