2013-03-22 14 views
8

Per il nostro buildbot, voglio visualizzare le filiali attive più recenti (non rilasciate). Diciamo che ho un ramo master, così come il seguente, dal più vecchio al più recente commettere:Come faccio a ottenere l'elenco dei rami non uniti in master, ordinati dal commit più recente?

  • branch1 (non fuse in master)
  • branch2 (fusa)
  • branch3 (non fusa)

Sono in grado di ottenere ciascuna di queste liste separatamente ... ad es. per ottenere tutti i rami non fuse in master:

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

O per ottenere i primi quindici rami, ordinato dai più recenti 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 

Così ho praticamente voglio che secondo elenco, meno branch2 (con o senza master). Spero che abbia senso?

+0

con git 2.7 (Q4 2015), 'git for-each-ref --no-fusione maestri refs/teste /' sarà possibile! Vedi [la mia risposta sotto] (http: // StackOverflow.it/a/32988584/6309) – VonC

risposta

11

Si potrebbe combinare le due cose, in questo modo:

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/#') 

che limiterà le for-each-ref al trattamento solo i rami che branch --no-merged rapporti ...

Edit: formattazione fisso di git branch uscita dopo in realtà il test ...

+0

hmm, 'errore: interruttore sconosciuto \'> '' –

+0

Non so da dove provenga questo messaggio - la riga di comando non contiene un'> '... In ogni caso, ho aggiornato il comando un po' dopo aver avuto una possibilità per provarlo veramente ... – twalberg

+0

Stesso errore: -/sia bash che zsh. –

1

Non puoi semplicemente saltare out2?

In sostanza, qualcosa di simile:

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; 

che ha funzionato per me dato l'output del campione.

+0

'grep: espressione regolare troppo grande' haha ​​ –

+0

Di quanti rami non seminati stai parlando? – spitzanator

+0

74, haha. Devo pulirne alcuni. –

0

con git 2.7 (Q4 2015), git for-each-ref, sosterrà l'opzione --no-merged

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

Con il doc:

--no-merged [<object>]: 

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


Vedi commit 4a71109, commit ee2bd06, commit f266c91, commit 9d306b5, commit 7c32834, commit 35257aa, commit 5afcb90, ..., commit b2172fd (7 luglio 2015), e commit af83baf (09 lug 2015) da Karthik Nayak (KarthikNayak).
(fusa per Junio C Hamano -- gitster -- in commit 9958dd8 05 ott 2015)

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 
Problemi correlati