2013-03-22 38 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 
相關問題