Git의 현재 지점 만 표시
이것을 위해 특별한 git 명령을 찾으려고했지만 찾을 수 없었습니다. 누구나 다음보다 짧거나 빠른 것을 제안 할 수 있습니까?
git branch | awk '/\*/ { print $2; }'
$ git rev-parse --abbrev-ref HEAD
master
이것은 Git 1.6.3 이상에서 작동합니다.
Git 1.8.1에서는 git symbolic-ref 명령을 "--short"옵션과 함께 사용할 수 있습니다 :
$ git symbolic-ref HEAD
refs/heads/develop
$ git symbolic-ref --short HEAD
develop
당신은 출력에 관심이있을 수 있습니다
git symbolic-ref HEAD
특히, 필요와 레이아웃에 따라하고 싶을 수도 있습니다
basename $(git symbolic-ref HEAD)
또는
git symbolic-ref HEAD | cut -d/ -f3-
그리고 다시 .git/HEAD
당신에게 관심을 가질만한 파일이 있습니다.
Git 2.22 (2019 년 2 분기)를 사용하면 더 간단한 접근 방식이 있습니다 git branch --show-current
.
Daniels Umanovskis ( )의 commit 0ecb1fc (2018 년 10 월 25 일)를 참조하십시오 . ( Junio C Hamano 에 의해 병합 - 커밋 3710f60 , 2019 년 3 월 07 일)umanovskis
gitster
branch
:--show-current
디스플레이 옵션 소개호출 할 때
--show-current
,git branch
현재 지점의 이름을 인쇄하고 종료합니다.
없이 실제 이름 만 인쇄됩니다refs/heads
.
분리 된 HEAD 상태에서는 아무것도 출력되지 않습니다.스크립팅 및 대화 형 / 정보 용으로 사용됩니다.
와 달리git branch --list
, 분기 이름을 얻기 위해 필터링이 필요하지 않습니다.
이것은 내가 방금 밟은 오래된 실입니다. 내가 알 수 있듯이 GIT의 현재 분기 만 기본적으로 표시 할 수있는 방법이 없으므로 다음을 사용하고 있습니다.
#> git branch | grep '*'
나는 이것이 빠르며 파이썬 API와 함께 사용할 수 있다고 생각합니다.
git branch --contains HEAD
* master
나는 사용하고있다
/etc/bash_completion.d/git
그것은 git과 함께 제공되며 지점 이름과 인수 완료와 함께 프롬프트를 제공합니다.
이것은 짧지는 않지만 분리 된 분기를 처리합니다.
git branch | awk -v FS=' ' '/\*/{print $NF}' | sed 's|[()]||g'
완성도 echo $(__git_ps1)
를 높이려면 Linux에서 최소한 괄호로 묶인 현재 분기의 이름을 제공해야합니다.
이것은 현재 분기를 표시하도록 bash 명령 프롬프트를 설정 하는 데 git 명령이 아니므로 (git에 따라) 일부 시나리오에서 유용 할 수 있습니다 .
예를 들면 다음과 같습니다.
/mnt/c/git/ConsoleApp1 (test-branch)>echo $(__git_ps1)
(test-branch)
/mnt/c/git/ConsoleApp1 (test-branch)>git checkout master
Switched to branch 'master'
/mnt/c/git/ConsoleApp1 (master)>echo $(__git_ps1)
(master)
/mnt/c/git/ConsoleApp1 (master)>cd ..
/mnt/c/git>echo $(__git_ps1)
/mnt/c/git>
누군가이 ( git show-branch --current) 도움 이 될 수 있습니다. 현재 분기는 * 표시로 표시됩니다.
host-78-65-229-191:idp-mobileid user-1$ git show-branch --current
! [CICD-1283-pipeline-in-shared-libraries] feat(CICD-1283): Use latest version of custom release plugin.
* [master] Merge pull request #12 in CORES/idp-mobileid from feature/fix-schema-name to master
--
+ [CICD-1283-pipeline-in-shared-libraries] feat(CICD-1283): Use latest version of custom release plugin.
+ [CICD-1283-pipeline-in-shared-libraries^] feat(CICD-1283): Used the renamed AWS pipeline.
+ [CICD-1283-pipeline-in-shared-libraries~2] feat(CICD-1283): Point to feature branches of shared libraries.
-- [master] Merge pull request #12 in CORES/idp-mobileid from feature/fix-schema-name to master
참고 URL : https://stackoverflow.com/questions/1417957/show-just-the-current-branch-in-git
'Programing' 카테고리의 다른 글
URL에서 서버로 파일 다운로드 (0) | 2020.03.08 |
---|---|
==와 strcmp를 사용한 문자열 비교 (0) | 2020.03.08 |
보다 쉬운 Windows 서비스 디버깅 방법 (0) | 2020.03.08 |
WPF 전역 예외 처리기 (0) | 2020.03.08 |
안드로이드에서 프로그래밍 방식으로 장치의 IMEI / ESN을 얻는 방법? (0) | 2020.03.08 |