최신 커밋으로 정렬된 Git 브랜치 목록을 가져오려면 어떻게 해야 합니까?
Git 저장소의 모든 브랜치 목록을 가져오고 싶습니다. Git 저장소의 브랜치 목록에는 "최신" 브랜치가 가장 최근에 커밋된 브랜치입니다(따라서 제가 주목하고 싶은 브랜치일 가능성이 높습니다.
Git을 사용하여 (a) 최신 커밋별로 브랜치 리스트를 정렬하거나 (b) 각 브랜치 리스트를 각 커밋 날짜와 함께 기계 판독 가능한 형식으로 가져올 수 있는 방법이 있습니까?
의 경우라면, 나는 ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★git branch 리스트를 하려면 , 그 해 주세요.그 후, 「브런치 」, 「브런치 리스트」, 「브런치 리스트」, 「브런치 리스트」, 「브런치 리스트」, 「브런치 리스트」를 참조해 주세요.git log -n 1 branchname --format=format:%ci각 지점의 약속 날짜를 가져옵니다.그러나 이것은 Windows 박스에서 실행되며, 새로운 프로세스의 회전은 상대적으로 비용이 많이 들기 때문에 브랜치가 많으면 Git 실행 파일을 브랜치별로 1회 실행하는 것이 느려질 수 있습니다.명령어 하나로 이 모든 것을 수행할 수 있는 방법이 있습니까?
다음 옵션을 사용합니다.
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
결과:

고급 사용:
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))'
결과:

프로용도(Unix):
하다 보면 수 있습니다.~/.gitconfig에는 recentb 에일리어스라는2개의할 수 있습니다.
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"
결과:
최근 커밋 순으로 정렬된 Git 브랜치 이름 목록...
Jakub의 답변과 Joe의 힌트를 확장하면 다음과 같이 "refs/heads/"가 삭제되어 출력에 브랜치 이름만 표시됩니다.
명령어:
git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'
결과:
다음은 최신 커밋이 있는 모든 브랜치를 나열하는 간단한 명령어입니다.
git branch -v
최신 커밋으로 주문하려면
git branch -v --sort=committerdate
출처 : http://git-scm.com/book/en/Git-Branching-Branch-Management
다음은 다른 두 가지 답을 조합한 최적의 코드입니다.
git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(authorname) %(refname:short)'
다음 별칭을 사용합니다.
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"
그 결과, 다음과 같이 됩니다.

커스텀 카운트를 설정할 수도 있습니다.
git recent 20(10월)
나는 앞의 예를 참고하여 나에게 가장 적합한 것을 만들 수 있었다.
git for-each-ref --committerdate refs/heads --format=read(authordate:short)%(color:red)%(color:short)%(color:short)%(color:color:short)%(color:color:short)%(color:color:color:color:color:commit)'입니다.
아래 코멘트에 제시된 바와 같이 리모트브런치 및 작성자 이름도 포함할 수 있습니다.
git for-each-ref --committerdate refs/heads refs/remotes --format(authordate:short) %(color:red) %(color:short) %(color:short) %(colorname)
다음으로 셸 프로파일에 쉽게 추가할 수 있는 셸 에일리어스로서 두 명령어를 나타냅니다.
# show a list of local git branches sorted by the commit date
alias git.branches='git for-each-ref --sort=-committerdate refs/heads --format="%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset))"'
# show a list of local and remote git branches sorted by the commit date
alias git.branches.remote='git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset)) %(authorname)"'
(은 직접 git 2.7 (2015년 4분기)을 합니다.git branch:
커밋 aa3bc55, 커밋 aedcb7d, 커밋 1511b22, 커밋 f65f139, ...(2015년 9월 23일), 커밋 aedcb7d, 커밋 1511b22, 커밋 ca41799(2015년 9월 24일), 커밋 f65f139, ...(2015년 9월 23일)KarthikNayak를 참조해 주세요.
(2015년 10월 15일 Junio C Hamano에 의해 병합됨----커밋 7f11b48에서)
특히 aedcb7d를 커밋합니다.
branch.c'를 사용합니다.ref-filterAPI
만들다branch.c는 '어느끼다'를 사용합니다ref-filterAPI를 사용하다'비밀번호'에서 됩니다.branch.c는 ''에 됩니다.ref-filter라이이「
지정된 키를 기준으로 정렬합니다.
「」-값의 내림차순으로 정렬합니다..
--sort=<key>이치노이 경우 마지막 키가 프라이머리 키가 됩니다.지원되는 키는 의 키와 동일합니다.
는 기본적으로 를 포함)에됩니다.refs/...prefix)를 지정합니다.여기에는 먼저 분리된 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의 9e46833(2015년 10월 30일)을 참조하십시오.
도움 : 하마노 gitster준오 ( )
(2015년 11월 3일 Junio C Hamano에 의해 병합됨----커밋 415095f)
" " " " " ) 。
--sort=objectsize) 두 ref가 동일한 값을 보유하고 있는 경우 폴백 비교는 이루어지지 않습니다.이로 인해 요하네스 식스트($gmane/280117)가 지적한 바와 같이 예기치 않은 결과가 발생할 수 있습니다(즉, 동일한 값의 참조를 나열하는 순서를 사전에 결정할 수 없습니다).따라서 다른 기준이 같을 때마다 참조 이름에 기반한 알파벳 비교로 폴백합니다.
$ git branch --sort=objectsize * (HEAD detached from fromtag) branch-two branch-one master
Git 2.19에서는 기본적으로 정렬 순서를 설정할 수 있습니다.
git branch는 Configuration을 합니다.branch.sort,맘에 들다git tag이 되어 있습니다.tag.sort.
Samuel Maftoul의 commit 560ae1c(2018년 8월 16일)를 참조하십시오.
(2018년 8월 27일, Junio C Hamano에 의해 합병 ----commit d89db6f에서)
branch.sort:
는 브런치가 로 표시되는 경우의 합니다.
git-branch.
없는 경우--sort=<value>을 지정하면 이됩니다." 라고 말합니다.
브랜치를하려면 , 「」를 사용합니다.git branch -r --sort=objectsize . 。-rflag를 지정하면 로컬브런치가 아닌 리모트브런치가 표시됩니다.
2.2020년),Git 2.27(2020년 2분기),git branch 및 " "기 " ""for-each-ref multiple " " " 。--sort=<key> 순위가 할 수 , "우선 순위"를 중심으로몇 .--ignore-case재명하다
Jeff King()peff의 7c5045f, 76f9e56(2020년 5월 3일)을 참조하십시오.
(2020년 5월 8일, Junio C Hamano에 의해 합병 ----commit 6de1630에서)
ref-filter: 모든 사용자 정렬 후에만 폴백 refname 정렬 적용서명자: Jeff King
9e468334b4를 커밋합니다(").
ref-filter: 알파벳 비교에 대한 폴백", 2015-10-30, Git v2.7.0-rc0 -- batch #10에 나열된 병합)은 ref-filter의 정렬을 ref-name 비교에 대한 폴백으로 가르쳤습니다.
잘못된 을 했다--sort모든 정렬 키가 소진된 후가 아니라 사용자로부터 키를 받습니다.은 하나의 '일단에 대해 작동했습니다.
--sort에는 안 .' 라고 말합니다.
첫 번째 키와 refname의 연결고리는 끊고 두 번째 키는 전혀 평가하지 않습니다.더 흥미로운 것은 이 폴백을 가끔 적용했다는 것입니다!
"와 같은taggeremail한 '는 그 해 드립니다.strcmp().
숫자 ',, 자, 자 but,value" "와 같은 입니다.taggerdate폴백을 적용했습니다.. 이 는 다항식 테스트를 합니다.taggeremail가장 큰 비교입니다.먼저 훨씬 더 엄격한 테스트를 추가해 보겠습니다.두 개의 태그 이메일, 날짜 및 참조 이름의 모든 조합을 표현하는 일련의 커밋이 있습니다.그러면 정렬이 올바른 우선순위로 적용되었는지 확인할 수 있으며 문자열과 값 비교기를 모두 누를 수 있습니다.
버그를 , 입니다.
compare_refs()기능하다ref_sorting이치노, 없다라는 말은 .
"ignore_case"ref_sorting하여 대조하지 이 어떻게 하는지 가 있습니다사용자 키를 사용하여 일치시키지 않았기 때문에 이러한 폴백이 무엇을 해야 하는지 논란의 여지가 있습니다.
하지만 지금까지는 이 깃발을 존중하려고 노력해 왔기 때문에 가장 침습이 적은 것은 계속 그렇게 하도록 노력하는 것입니다.
현재 코드의 모든 발신자는 모든 키에 대해 플래그를 설정하거나 설정하지 않기 때문에 첫 번째 키에서 플래그를 꺼낼 수 있습니다.하지 않는 하기 위해 대소문자를 하는 것이 .--ignore-case
Git 2.31 (Q1 2021)로 정리된 "wrt the dispected HEAD display"의 git branch --sort(man)실장은 항상 해킹되어 왔다.
commit 4045f65, commit 2708ce6, commit 7c269a7, commit d094748, commit 75c50e5(2021년 1월07일) 및 commit 08bf6a8, commit fdd02a(2021년 1월06일) by Avar Arnfjörd Bjarmason()avar를 참조하십시오.
(Junio C Hamano에 의해 병합 ----commit 9e409d7, 2021년 1월 25일)
: 리버스 정렬 아래에 "HEAD disparted"를 먼저 표시합니다
branch.서명자 : Avar Arnfjörd Bjarmason
「」
git branch -l --sort=-objectsize(man)등의 출력을 변경해, 「」를 표시합니다.(HEAD detached at <hash>)출력 시작 시 " 메시지가 표시됩니다.
<고객명>님 앞compare_detached_head()이전 커밋에 추가된 함수는 비상 효과로 이 출력을 내보냅니다.의 크기, 기타 을것은 의미가 .
(HEAD detached at <hash>)입니다." 메시지를 정렬합니다.
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
애초에 정렬된 유일한 이유는 우리가 이것을 레프 필터 기계에 주입하기 때문에 "내가 분리되었는가?" 탐지를 할 필요가 없기 때문입니다.
Git 2.35 (2022년 1분기)에서는,git -c branch.sort=bogus branch new HEAD(man) 「」와 같은 것.
정렬 키 정보가 필요 없는 git branch(man)" " 명령어 동작 모드입니다.가짜 정렬 키를 확인해도 오류가 발생하지 않습니다.
Junio C Hamano()gitster의 commit 98e7ab6, commit 1a89796 (2021년 10월 20일)을 참조하십시오.
(커밋 5126145, 2021년 11월 29일 Junio C Hamano에 의해 병합됨)
for-each-ref: 해석 지연--sort=<atom>(옵션)
for-each-ref패밀리는 각 명령어가 를 호출합니다.--sort=<atom>명령줄에 도 전에 .<atom>인식되지 않습니다.리스트에 하여 ""로 합니다.
ref_sorting★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
그 결과, 「」는,git branch --sort=bogus -h(man) 기능이라고 해도 좋을지도 모르는 짧은 도움의 제공에 실패해, 현재는, 다른 옵션과 보다 일관성이 있다.
색상, 태그 및 중복되지 않은 원격 참조도 필요했습니다.
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'"]++'"
Git 2.19에서는 다음과 같이 간단하게 할 수 있습니다.
git branch --sort=-committerdate
다음 항목도 있습니다.
git config branch.sort -committerdate
따라서 현재 저장소의 브랜치를 나열할 때마다 committerdate별로 정렬하여 나열됩니다.
브런치를 리스트 할 때마다 comitter date 순으로 정렬할 경우:
git config --global branch.sort -committerdate
면책사항:저는 Git의 이 기능의 저자이며, 이 질문을 보고 구현했습니다.
또 다른 변형:
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
은 통과를 것 .-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리모트 포인트와 로컬브런치를 모두 표시합니다.
다음 명령어는 내 목적에 도움이 됩니다.
git branch --sort=-committerdate | head -n 10
최신 10개의 브랜치가 표시됩니다.짧고 가명 없이 사용할 수 있습니다.
저는 상대 날짜를 사용하고 지점 이름을 다음과 같이 단축하는 것을 좋아합니다.
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)$|$"
커밋 날짜를 기준으로 정렬된 상위 5개 지점 이름만 가져옵니다.
git branch --sort=-committerdate | head -5
더합니다(이후).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"
다음 명령어를 생각해냈습니다(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
나는 다양한 작품들이 어떻게 작동하는지 블로그에 글을 썼다.
저도 같은 문제가 있어서 Twig라는 루비 보석을 썼어요.분기가 시간순으로 나열되며(최신 순서부터), 모든 분기가 나열되지 않도록(많이 있는 경우) 최대 경과 기간을 설정할 수도 있습니다.예를 들어 다음과 같습니다.
$ 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/
참고로 최근에 체크아웃한 브랜치(최근 커밋된 브랜치가 아닌) 목록을 가져오고 싶다면 Git의 reflog를 사용할 수 있습니다.
$ git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | head -n5
master
stable
master
some-cool-feature
feature/improve-everything
다음 항목도 참조하십시오.최근에 체크 아웃한 Git 브랜치 리스트를 입수하려면 어떻게 해야 하나요?
다음은 최근 브랜치 전환에 사용하는 간단한 스크립트입니다.
#!/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
다음의 2개의 에일리어스를 사용합니다.
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개)과 각각 번호가 표시됩니다.지점 번호를 입력하면 다음 항목이 체크 아웃됩니다.
Git v2.19 도입branch.sort설정 옵션(branch.display 참조).
★★★★★★★★★★★★★★★★★.git branch에 정렬되며, 디폴트로는 커밋 날짜(내림차순)는 「커밋 날짜」로 표시됩니다.
# gitconfig
[branch]
sort = -committerdate # Descending
스크립트:
git config --global branch.sort -committerdate
그렇게,
git branch
출력:
* dev
master
_
그리고.
git branch -v
출력:
* dev 0afecf5 Merge branch 'oc' into dev
master 652428a Merge branch 'dev'
_ 7159cf9 Merge branch 'bashrc' into dev
일반적으로 최근에는 리모트 브랜치를 고려하고 있습니다.그러니까 이거 먹어봐
git fetch
git for-each-ref --sort=-committerdate refs/remotes/origin
다른 모든 스크립트가 수행하는 작업을 수행하는 다른 스크립트가 있습니다.사실, 이것은 당신의 셸을 위한 기능을 제공합니다.
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}"
}
이는 saedgnu 버전을 기반으로 하지만 현재 분기는 별과 컬러로 표시되며, "months" 또는 "years"라고 표현되지 않은 것만 표시합니다.
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
스크립트로 얻은 최고의 결과:
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
허용된 명령줄 답변은 충격적이지만 GUI와 같이 더 예쁜 것을 원하는 경우 원본 === "github"입니다.
저장소에서 "분기"를 클릭할 수 있습니다.또는 직접 URL https://github.com/ORGANIZATION_NAME/REPO_NAME/branches을 방문하십시오.
마지막 커밋 날짜와 함께 인쇄하는 가장 간단한 방법:
git branch --all --format='%(committerdate:short) %(refname:short)'|sort
git for-each-ref --sort=-committerdate refs/heads/
# Or using Git branch (since version 2.7.0)
git branch --sort=-committerdate # Descending
git branch --sort=committerdate # Ascending
다음은 제가 찾고 있던 종류입니다.
git for-each-ref --sort=-committerdate --format='%(committerdate)%09%(refname:short)' refs/heads/ | tail -r
★★★tail -r 인식된 "" " " " " " 입니다.commiterdate지막입입니니다
이미 많은 답변이 있다는 것을 알지만, 간단한 가명에 대한 저의 의견은 다음과 같습니다(최신 브랜치를 하단에 두고 싶습니다).
[alias]
br = !git branch --sort=committerdate --color=always | tail -n15
[color "branch"]
current = yellow
local = cyan
remote = red
최신 15개 브랜치의 개요를 컬러로 표시하여 현재 브랜치가 강조 표시되어 있습니다(아스타리스크가 붙어 있습니다).
합니다.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다음에. 거.그. it. ㅇㅇ.git config --global alias.rb '!git_recent_branches.sh'을 git rb명령어를 입력합니다.
언급URL : https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
'programing' 카테고리의 다른 글
| PowerShell의 $?와 $LastExitCode의 차이 (0) | 2023.04.18 |
|---|---|
| 연결 매니저에 대한 AcquireConnection 메서드 호출이 오류 코드 0xC0202009로 실패했습니다. (0) | 2023.04.18 |
| WindowStyle=None으로 WPF 창 상단에 있는 흰색 띠를 제거하는 방법 (0) | 2023.04.18 |
| SED가 모든 항목을 대체하지 못하는 이유는 무엇입니까? (0) | 2023.04.18 |
| 마이크로소프트(MS.Office.Interop.엑셀은 매우 느리다. (0) | 2023.04.18 |




