질문자 :Joe White
Git 리포지토리의 모든 분기 목록을 맨 위에 "가장 최신" 분기가 있는 목록을 가져오고 싶습니다. 여기서 "가장 최신" 분기는 가장 최근에 커밋된 것이므로 주목하고 싶다).
Git을 사용하여 (a) 최신 커밋별로 분기 목록을 정렬하거나 (b) 일종의 기계 판독 형식으로 분기 목록을 각 분기의 마지막 커밋 날짜와 함께 가져올 수 있는 방법이 있습니까?
최악의 경우에는 항상 git branch
를 실행하여 모든 분기의 목록을 얻고 출력을 구문 분석한 다음 git log -n 1 branchname --format=format:%ci
를 실행하여 각 분기의 커밋 날짜를 얻을 수 있습니다. 그러나 이것은 새 프로세스를 시작하는 데 상대적으로 비용이 많이 드는 Windows 상자에서 실행되므로 분기당 한 번 Git 실행 파일을 시작하는 것은 분기가 많으면 느려질 수 있습니다. 단일 명령으로 이 모든 작업을 수행할 수 있는 방법이 있습니까?
git for-each-ref
--sort=-committerdate
옵션을 사용하십시오.
git branch
용 Git 2.7.0부터 사용할 수도 있습니다.
기본 사용법:
git for-each-ref --sort=-committerdate refs/heads/ # Or using git branch (since version 2.7.0) git branch --sort=-committerdate # DESC git branch --sort=committerdate # ASC
결과:
![결과](https://i.imgur.com/AlaP8dD.png)
고급 사용법:
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
결과:
![결과](https://i.imgur.com/tDCTiZx.png)
전문가용(Unix):
다음 스니펫을 ~/.gitconfig
에 넣을 수 있습니다. 최근 b 별칭은 두 개의 인수를 허용합니다.
-
refbranch
:에 대해 계산되는 지점 앞서 및 열 뒤에. 기본 마스터 -
count
: 표시할 최근 분기 수. 기본값 20
[alias] # ATTENTION: All aliases prefixed with ! run in /bin/sh make sure you use sh syntax, not bash/zsh or whatever recentb = "!r() { refbranch=$1 count=$2; git for-each-ref --sort=-committerdate refs/heads --format='%(refname:short)|%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always --count=${count:-20} | while read line; do branch=$(echo \"$line\" | awk 'BEGIN { FS = \"|\" }; { print $1 }' | tr -d '*'); ahead=$(git rev-list --count \"${refbranch:-origin/master}..${branch}\"); behind=$(git rev-list --count \"${branch}..${refbranch:-origin/master}\"); colorline=$(echo \"$line\" | sed 's/^[^|]*|//'); echo \"$ahead|$behind|$colorline\" | awk -F'|' -vOFS='|' '{$5=substr($5,1,70)}1' ; done | ( echo \"ahead|behind||branch|lastcommit|message|author\\n\" && cat) | column -ts'|';}; r"
결과:
![최근 별칭 결과](https://i.stack.imgur.com/Q8Buq.png)
Jakub Narębski가장 최근 커밋 순으로 정렬된 Git 브랜치 이름 목록…
Jakub의 답변 과 Joe의 팁을 확장하면 다음은 "refs/heads/"를 제거하여 출력에 분기 이름만 표시됩니다.
명령:
git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'
결과:
![최근 Git 브랜치](https://i.stack.imgur.com/MYOCB.png)
Beau Smith다음은 최신 커밋이 있는 모든 분기를 나열하는 간단한 명령입니다.
git branch -v
가장 최근 커밋을 기준으로 정렬하려면 다음을 사용하십시오.
git branch -v --sort=committerdate
출처: http://git-scm.com/book/en/Git-Branching-Branch-Management
user1682406다음은 다른 두 가지 답변을 결합한 최적의 코드입니다.
git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(authorname) %(refname:short)'
nikolay다음 별칭을 사용합니다.
recent = "!r() { count=$1; git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always --count=${count:=10} | column -ts'|'}; r"
다음을 생성합니다.
![결과](https://i.stack.imgur.com/iGn5R.png)
사용자 지정 개수를 지정할 수도 있습니다. 예:
git recent 20
(기본값은 10).
dimid이전 예제를 참조하여 나에게 가장 적합한 것을 만들 수 있었습니다.
git for-each-ref --sort=-committerdate refs/heads/ --format='%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short )%(색상:재설정) (%(색상:녹색)%(커미터 날짜:상대)%(색상:재설정))'
![출력 스크린샷](https://i.stack.imgur.com/XrfBr.png)
Andrew또한 중복되지 않은 색상, 태그 및 원격 참조가 필요했습니다.
for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '! a[$0]++'
인용이 어려울 수 있으므로 다음은 Bash의 별칭입니다.
alias glist='for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '"'! a["'$0'"]++'"
estanigit 2.7(2015년 4분기)에서는 직접 git branch
사용하여 분기 정렬을 도입합니다.
참조 aa3bc55 커밋 , aedcb7d 커밋 , 1511b22 커밋 , f65f139 커밋 , (2015 9월 23일), aedcb7d 커밋 , 1511b22 커밋 , ca41799을 커밋 (2015년 9월 24일), 및 f65f139 커밋 , (23 년 9 월 2015)에 의해 KARTHIK 나약 ( KarthikNayak
) .
(2015년 10월 15일 커밋 7f11b48 에서 Junio C gitster
-- gitster -- 병합)
특히 aedcb7d를 커밋합니다 .
branch.c
: ' ref-filter
' API 사용
참조 정렬을 통해 반복하기 위해 ' branch.c
'가 ' ref-filter
branch.c
'에서 사용된 대부분의 코드를 제거 ref-filter
' 라이브러리에 대한 호출로 대체합니다.
--sort=<key>
옵션을 추가합니다 .
주어진 키를 기준으로 정렬합니다.
접두사 -
값의 내림차순으로 정렬합니다.
--sort=<key>
옵션을 여러 번 사용할 수 있으며 이 경우 마지막 키가 기본 키가 됩니다.
지원되는 키 git for-each-ref
의 키와 동일 합니다.
정렬 순서는 기본적으로 전체 참조 이름( refs/...
접두사 포함)을 기반으로 정렬됩니다. 이것은 분리된 HEAD(있는 경우)를 먼저 나열한 다음 로컬 분기를 나열하고 마지막으로 원격 추적 분기를 나열합니다.
여기:
git branch --sort=-committerdate
또는 (아래 Git 2.19 참조)
# if you are sure to /always/ want to see branches ordered by commits: git config --global branch.sort -committerdate git branch
Karthik Nayak( KarthikNayak
)의 commit 9e46833 (2015년 10월 30일)도 참조하십시오.
도움: Junio C gitster
( gitster ) .
(2015년 11월 3일 커밋 415095f 에서 Junio C gitster
-- gitster -- 병합)
숫자 값에 따라 정렬할 때(예: --sort=objectsize
) 두 참조가 동일한 값을 보유할 때 대체 비교가 없습니다. 이로 인해 Johannes Sixt( $gmane/280117 )가 지적한 바와 같이 예기치 않은 결과가 발생할 수 있습니다(즉, 동일한 값으로 ref를 나열하는 순서를 미리 결정할 수 없음).
따라서 다른 기준이 같을 때마다 참조 이름을 기반으로 한 알파벳 비교로 대체합니다 .
$ git branch --sort=objectsize * (HEAD detached from fromtag) branch-two branch-one master
Git 2.19에서는 기본적으로 정렬 순서를 설정할 수 있습니다.
git branch
는 이미 config tag.sort
git tag
와 같은 branch.sort
지원합니다.
Samuel Maftoul(``)의 commit 560ae1c (2018년 8월 16일)를 참조하십시오.
(2018년 8월 27일 d89db6f 커밋 에서 Junio C gitster
-- gitster -- 병합)
branch.sort:
git-branch
의해 표시될 때 분기의 정렬 순서를 제어합니다.
--sort=<value>
" 옵션을 제공하지 않으면 이 변수의 값이 기본값으로 사용됩니다.
원격 분기를 나열하려면 git branch -r --sort=objectsize
. -r
플래그는 로컬 분기 대신 원격 분기를 나열하도록 합니다.
Git 2.27(2020년 2분기)에서는 " git branch
" 및 기타 " for-each-ref
" 변형이 우선 순위가 높은 순서로 --sort=<key>
--ignore-case
" 처리 및 refname과의 타이 브레이킹이 수정되었습니다.
Jeff King( peff
)의 commit 7c5045f , commit 76f9e56 (2020년 5월 3일)을 참조하십시오.
( Junio C gitster
-- gitster -- 커밋 6de1630 , 2020년 5월 8일 병합)
ref-filter
: 모든 사용자가 정렬한 후에만 대체 참조 이름 정렬을 적용합니다.
서명자: Jeff King
Commit 9e468334b4 (" ref-filter
: fallback on alphabetical comparison", 2015-10-30, Git v2.7.0-rc0 -- merge list in batch #10 )는 ref-filter의 정렬을 참조 이름 비교로 대체하도록 가르쳤습니다.
그러나 모든 정렬 키가 소진된 후가 아니라 사용자 --sort
" 키에 대한 비교 결과를 재정의하여 잘못된 수준에서 수행했습니다.
이것은 단일 " --sort
" 옵션에서는 올바르게 작동했지만 여러 옵션에서는 작동하지 않았습니다.
우리는 refname과 함께 첫 번째 키의 연결을 끊고 두 번째 키를 전혀 평가하지 않습니다.
문제를 더욱 흥미롭게 만들기 위해 이 대체를 가끔만 적용했습니다!
문자열 비교가 필요한 taggeremail
"과 같은 필드 strcmp()
의 결과가 0이더라도 실제로 반환합니다.
taggerdate
"와 같은 숫자 " value
" 필드의 경우 대체를 적용했습니다. 이것이 다중 정렬 테스트가 이것을 놓친 이유 taggeremail
을 주요 비교로 사용합니다.
따라서 훨씬 더 엄격한 테스트를 추가하여 시작하겠습니다. 두 개의 태거 이메일, 날짜 및 참조 이름의 모든 조합을 표현하는 커밋 세트가 있습니다. 그런 다음 정렬이 올바른 우선 순위로 적용되었는지 확인할 수 있으며 문자열 및 값 비교기를 모두 사용할 것입니다.
그것은 버그를 보여주고 수정은 간단합니다. 모든 ref_sorting
키가 소진된 compare_refs()
외부 함수에는 "ignore_case"
ref_sorting
요소의 일부이기 때문입니다. 우리가 일치시키기 위해 사용자의 키를 사용하지 않았기 때문에 그러한 대체가 무엇을 해야 하는지는 논쟁의 여지가 있습니다.
그러나 지금까지 우리는 그 깃발을 존중하려고 노력해왔기 때문에 가장 덜 침습적인 것은 계속 그렇게 하는 것입니다.
현재 코드의 모든 호출자는 모든 키에 대해 플래그를 설정하거나 없음에 대해 플래그를 설정하므로 첫 번째 키에서 플래그를 가져올 수 있습니다. 사용자가 키의 대소문자 구분을 실제로 뒤집을 수 있는 가상의 세계에서는 해당 대소문자를 블랭킷 " --ignore-case
"와 구별하기 위해 코드를 확장할 수 있습니다.
분리된 HEAD 디스플레이를 사용하는 " git branch --sort
" ( man ) 구현은 항상 해키였으며 Git 2.31(2021년 1분기)로 정리되었습니다.
커밋 4045f65 , 커밋 2708ce6 , 커밋 7c269a7 , 커밋 d094748 , 커밋 75c50e5 (2021년 1월 7일) 및 커밋 08bf6a8 , 커밋 ffdd02a (06 Jan avar
) 작성
(2021년 1월 25일 9e409d7 커밋 에서 Junio C gitster
-- gitster -- 병합)
branch
: 역순 정렬에서 "HEAD detached"를 먼저 표시
사인오프: Ævar Arnfjörð Bjarmason
git branch -l --sort=-objectsize
" ( man ) 같은 출력을 변경하여 출력 시작 부분에 " (HEAD detached at <hash>)
" 메시지를 표시합니다.
compare_detached_head()
함수가 추가되기 전에 이 출력을 긴급 효과로 내보냈습니다.
(HEAD detached at <hash>)
" 메시지의 개체 크기, 유형 또는 기타 비속성을 고려하는 것은 의미가 없습니다.
대신 항상 상단에서 방출하도록 합시다.
처음에 정렬된 유일한 이유는 이를 ref-filter 기계에 주입하여 builtin/branch.c
가 자체적으로 "내가 분리되었습니까?"를 수행할 필요가 없기 때문입니다. 발각.
VonC-vv
를 전달하여 자세한 출력을 얻는 것을 허용하지 않는 것 같습니다.
다음은 커밋 날짜별로 git branch -vv
를 정렬하고 색상을 유지하는 한 줄짜리입니다.
git branch -vv --color=always | while read; do echo -e $(git log -1 --format=%ct $(echo "_$REPLY" | awk '{print $2}' | perl -pe 's/\e\[?.*?[\@-~]//g') 2> /dev/null || git log -1 --format=%ct)"\t$REPLY"; done | sort -r | cut -f 2
커밋 날짜를 추가로 인쇄하려면 이 버전을 대신 사용할 수 있습니다.
git branch -vv --color=always | while read; do echo -e $(git log -1 --format=%ci $(echo "_$REPLY" | awk '{print $2}' | perl -pe 's/\e\[?.*?[\@-~]//g') 2> /dev/null || git log -1 --format=%ci)" $REPLY"; done | sort -r | cut -d ' ' -f -1,4-
샘플 출력:
2013-09-15 master da39a3e [origin/master: behind 7] Some patch 2013-09-11 * (detached from 3eba4b8) 3eba4b8 Some other patch 2013-09-09 my-feature e5e6b4b [master: ahead 2, behind 25] WIP
여러 줄로 나누는 것이 더 읽기 쉽습니다.
git branch -vv --color=always | while read; do # The underscore is because the active branch is preceded by a '*', and # for awk I need the columns to line up. The perl call is to strip out # ansi colors; if you don't pass --color=always above you can skip this local branch=$(echo "_$REPLY" | awk '{print $2}' | perl -pe 's/\e\[?.*?[\@-~]//g') # git log fails when you pass a detached head as a branch name. # Hide the error and get the date of the current head. local branch_modified=$(git log -1 --format=%ci "$branch" 2> /dev/null || git log -1 --format=%ci) echo -e "$branch_modified $REPLY" # cut strips the time and timezone columns, leaving only the date done | sort -r | cut -d ' ' -f -1,4-
git branch
다른 인수와 함께 작동해야 합니다. 예를 들어 -vvr
을 사용하여 원격 추적 분기 -vva
를 사용하여 원격 추적 및 로컬 분기를 모두 나열합니다.
John MellorGit 2.19부터 간단하게 다음을 수행할 수 있습니다.
git branch --sort=-committerdate
당신은 또한 수:
git config branch.sort -committerdate
따라서 현재 저장소에 분기를 나열할 때마다 committerdate별로 정렬되어 나열됩니다.
분기를 나열할 때마다 comitterdate별로 정렬하려는 경우:
git config --global branch.sort -committerdate
면책 조항: 저는 Git에서 이 기능의 작성자이며 이 질문을 보고 구현했습니다.
user801247나는 상대 날짜를 사용하고 다음과 같이 지점 이름을 줄이는 것을 좋아합니다.
git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads
결과는 다음과 같습니다.
21 minutes ago nathan/a_recent_branch 6 hours ago master 27 hours ago nathan/some_other_branch 29 hours ago branch_c 6 days ago branch_d
좋아하는 별칭을 모두 추가한 다음 스크립트를 팀에 공유하기 위해 Bash 파일을 만드는 것이 좋습니다. 다음은 이것만 추가하는 예입니다.
#!/bin/sh git config --global alias.branches "!echo ' ------------------------------------------------------------' && git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads && echo ' ------------------------------------------------------------'"
그런 다음 이 작업을 수행하여 멋지게 형식이 지정되고 정렬된 로컬 분기 목록을 얻을 수 있습니다.
git branches
업데이트: 색칠을 하려면 다음을 수행하십시오.
#!/bin/sh # (echo ' ------------------------------------------------------------' && git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads && echo ' ------------------------------------------------------------') | grep --color -E "$(git rev-parse --abbrev-ref HEAD)$|$"
n8tr약간의 색상을 추가합니다( pretty-format
사용할 수 없기 때문에).
[alias] branchdate = for-each-ref --sort=-committerdate refs/heads/ --format="%(authordate:short)%09%(objectname:short)%09%1B[0;33m%(refname:short)%1B[m%09"
epylinkn다음 명령을 생각해 냈습니다(Git 2.13 이상).
git branch -r --sort=creatordate \ --format "%(creatordate:relative);%(committername);%(refname:lstrip=-1)" \ | grep -v ";HEAD$" \ | column -s ";" -t
column
이 없으면 마지막 줄을 다음으로 바꿀 수 있습니다.
| sed -e "s/;/\t/g"
출력은 다음과 같습니다.
6 years ago Tom Preston-Werner book 4 years, 4 months ago Parker Moore 0.12.1-release 4 years ago Matt Rogers 1.0-branch 3 years, 11 months ago Matt Rogers 1.2_branch 3 years, 1 month ago Parker Moore v1-stable 12 months ago Ben Balter pages-as-documents 10 months ago Jordon Bedwell make-jekyll-parallel 6 months ago Pat Hawks to_integer 5 months ago Parker Moore 3.4-stable-backport-5920 4 months ago Parker Moore yajl-ruby-2-4-patch 4 weeks ago Parker Moore 3.4-stable 3 weeks ago Parker Moore rouge-1-and-2 19 hours ago jekyllbot master
다양한 부품이 작동하는 방식에 대한 블로그 게시물을 작성했습니다.
bdesham저도 같은 문제가 있어서 Twig 라는 Ruby gem을 작성했습니다. 분기를 시간순으로 나열하고(최신 항목부터), 모든 분기를 나열하지 않도록 최대 기간을 설정할 수도 있습니다(많은 분기가 있는 경우). 예를 들어:
$ twig issue status todo branch ----- ------ ---- ------ 2013-01-26 18:00:21 (7m ago) 486 In progress Rebase optimize-all-the-things 2013-01-26 16:49:21 (2h ago) 268 In progress - whitespace-all-the-things 2013-01-23 18:35:21 (3d ago) 159 Shipped Test in prod * refactor-all-the-things 2013-01-22 17:12:09 (4d ago) - - - development 2013-01-20 19:45:42 (6d ago) - - - master
또한 각 지점에 대한 사용자 지정 속성(예: 티켓 ID, 상태, 할 일)을 저장하고 이러한 속성에 따라 지점 목록을 필터링할 수 있습니다. 추가 정보: http://rondevera.github.io/twig/
Ron DeVera참고로 최근에 확인된 분기 목록(최근에 커밋된 것과는 대조적으로)을 얻으려면 Git의 reflog를 사용할 수 있습니다.
$ git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | head -n5 master stable master some-cool-feature feature/improve-everything
참조: 최근에 체크아웃한 Git 브랜치 목록을 얻으려면 어떻게 해야 합니까?
Jordan Brough다음은 최근 분기 간에 전환하는 데 사용하는 작은 스크립트입니다.
#!/bin/bash # sudo bash re='^[0-9]+$' if [[ "$1" =~ $re ]]; then lines="$1" else lines=10 fi branches="$(git recent | tail -n $lines | nl)" branches_nf="$(git recent-nf | tail -n $lines | nl)" echo "$branches" # Prompt which server to connect to max="$(echo "$branches" | wc -l)" index= while [[ ! ( "$index" =~ ^[0-9]+$ && "$index" -gt 0 && "$index" -le "$max" ) ]]; do echo -n "Checkout to: " read index done branch="$( echo "$branches_nf" | sed -n "${index}p" | awk '{ print $NF }' )" git co $branch clear
이 두 가지 별칭 사용:
recent = for-each-ref --sort=committerdate refs/heads/ --format=' %(color:blue) %(authorname) %(color:yellow)%(refname:short)%(color:reset)' recent-nf = for-each-ref --sort=committerdate refs/heads/ --format=' %(authorname) %(refname:short)'
Git 리포지토리에서 호출하면 마지막 N 분기(기본적으로 10개)와 각각의 번호가 표시됩니다. 지점 번호를 입력하면 다음과 같이 체크아웃됩니다.
![여기에 이미지 설명 입력](https://i.stack.imgur.com/pvuZq.png)
Agus Arias다른 변형:
git branch -r --sort=-committerdate --format='%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always | column -ts'|'
원격 분기의 변경 사항을 살펴보고 있더라도 명령을 실행하기 전에 원본과 동기화할 가치가 있습니다(git fetch를 사용할 수 있음). 로컬 Git 폴더가 업데이트되지 않은 경우 오래된 정보를 반환할 수 있기 때문입니다. 잠시.
또한 이것은 Windows cmd 및 PowerShell에서 작동하는 버전입니다.
git branch -r --sort=-committerdate --format="%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)" --color=always
ZenoArrow일반적으로 최근에 원격 분기를 고려합니다. 그래서 이것을 시도
git fetch git for-each-ref --sort=-committerdate refs/remotes/origin
Victor Choy다음은 다른 모든 스크립트가 수행하는 작업을 수행하는 또 다른 스크립트입니다. 실제로 쉘에 대한 기능을 제공합니다.
기여도는 Git 구성에서 일부 색상을 가져오거나 기본값을 사용한다는 것입니다.
# Git Branch by Date # Usage: gbd [ -r ] gbd() { local reset_color=`tput sgr0` local subject_color=`tput setaf 4 ; tput bold` local author_color=`tput setaf 6` local target=refs/heads local branch_color=`git config --get-color color.branch.local white` if [ "$1" = -r ] then target=refs/remotes/origin branch_color=`git config --get-color color.branch.remote red` fi git for-each-ref --sort=committerdate $target --format="${branch_color}%(refname:short)${reset_color} ${subject_color}%(subject)${reset_color} ${author_color}- %(authorname) (%(committerdate:relative))${reset_color}" }
joeytwiddle이것은 saeedgnu의 버전을 기반으로 하지만 현재 분기가 별과 색상으로 표시되고 "개월" 또는 "년"으로 설명되지 않은 항목만 표시됩니다.
current_branch="$(git symbolic-ref --short -q HEAD)" git for-each-ref --sort=committerdate refs/heads \ --format='%(refname:short)|%(committerdate:relative)' \ | grep -v '\(year\|month\)s\? ago' \ | while IFS='|' read branch date do start=' ' end='' if [[ $branch = $current_branch ]]; then start='* \e[32m' end='\e[0m' fi printf "$start%-30s %s$end\\n" "$branch" "$date" done
Mark Lodato스크립트로서의 최고의 결과:
git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short)|%(committerdate:iso)|%(authorname)' | sed 's/refs\/heads\///g' | grep -v BACKUP | while IFS='|' read branch date author do printf '%-15s %-30s %s\n' "$branch" "$date" "$author" done
saeedgnugit branch --sort=-committerdate | head -5
커미터 날짜를 기준으로 상위 5개 분기 이름만 정렬하는 데 관심이 있는 사람을 위한 것입니다.
unknownerror허용되는 명령줄 대답은 훌륭하지만 GUI와 같은 더 예쁜 것을 원하고 원본 === "github"를 원할 경우.
저장소에서 "분기"를 클릭할 수 있습니다. 또는 URL을 직접 누르십시오: https://github.com/ORGANIZATION_NAME/REPO_NAME/branches
jahrichie마지막 커밋 날짜와 함께 인쇄하는 가장 간단한 것:
git branch --all --format='%(committerdate:short) %(refname:short)'|sort
Saurav Sahugit for-each-ref --sort=-committerdate refs/heads/ # Or using git branch (since version 2.7.0) git branch --sort=-committerdate # DESC git branch --sort=committerdate # ASC
Ikbel benab내가 찾던 변형은 다음과 같습니다.
git for-each-ref --sort=-committerdate --format='%(committerdate)%09%(refname:short)' refs/heads/ | tail -r
그 tail -r
commiterdate
가 마지막이 되도록 목록을 뒤집습니다.
Ben허용된 답변의 출력을 dialog
로 파이프하여 대화형 목록을 제공합니다.
#!/bin/bash TMP_FILE=/tmp/selected-git-branch eval `resize` dialog --title "Recent Git Branches" --menu "Choose a branch" $LINES $COLUMNS $(( $LINES - 8 )) $(git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short) %(committerdate:short)') 2> $TMP_FILE if [ $? -eq 0 ] then git checkout $(< $TMP_FILE) fi rm -f $TMP_FILE clear
(예) ~/bin/git_recent_branches.sh
및 chmod +x
합니다. 그런 다음 git config --global alias.rb '!git_recent_branches.sh'
새 git rb
명령을 제공합니다.
John Delaney이미 많은 답변이 있다는 것을 알고 있지만 여기에 간단한 별칭에 대한 2센트가 있습니다(저는 가장 최근 분기를 맨 아래에 두는 것을 좋아합니다).
[alias] br = !git branch --sort=committerdate --color=always | tail -n15 [color "branch"] current = yellow local = cyan remote = red
이렇게 하면 현재 분기가 강조 표시된(별표가 있음) 최신 15개 분기에 대한 멋진 개요를 색상으로 제공합니다.
Tom별칭을 설정하려고 할 때 bash_profile의 Mac에서 작은 따옴표를 처리하는 데 문제가 있었습니다. 이 답변은 " 작은따옴표 문자열 내에서 작은따옴표를 이스케이프 처리하는 방법 "을 해결하는 데 도움이 되었습니다.
작업 솔루션:
alias gb='git for-each-ref --sort=committerdate refs/heads/ --format='"'"'%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"'"''
추신: 내 평판 때문에 댓글을 달 수 없습니다.
Aditya Kadamgit for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
이것은 당신이 필요로 하는 것입니다
ChunkCoder출처 : http:www.stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit