어떤 Git 브랜치가 어떤 원격 / 업스트림 브랜치를 추적하는지 어떻게 알 수 있습니까?
나는 내가 할 수 있다는 것을 알고 git branch --all
있고 그것은 나에게 로컬 브랜치와 원격 브랜치를 보여 주지만 그들 사이의 관계를 보여주는 데 그다지 유용하지 않다.
어떤 로컬 지점이 어떤 원격 지점을 추적하는지 보여주는 방식으로 지점을 나열하려면 어떻게해야합니까?
스크립팅을 위해 이것을 원한다면 좋지 않은 도자기 명령입니다.
git branch -vv # doubly verbose!
git 1.8.3에서는 업스트림 분기가 파란색 으로 표시됩니다 ( " git에서이 분기 추적 (있는 경우)은 무엇입니까? "참조).
깨끗한 출력을 원하면 arcresu의 답변을 참조하십시오. 원래이 답변을 작성했을 때 존재하지 않았던 porcelain 명령을 사용하므로 조금 더 간결하고 병합뿐만 아니라 rebase 용으로 구성된 분기와 함께 작동합니다.
git remote show origin
'origin'을 리모컨의 이름으로 바꾸십시오.
의 man 페이지를 보면 git-rev-parse
다음 구문이 설명되어 있음을 알 수 있습니다.
<branchname>@{upstream}
예를 들면master@{upstream}
,@{u}
@{upstream}
브랜치 이름에 대한 접미사 (약식<branchname>@{u}
)는 브랜치 이름에 지정된 브랜치가 위에 빌드되도록 설정된 브랜치를 나타냅니다. 누락 된 분기 이름의 기본값은 현재 이름입니다.
따라서 분기의 업스트림을 찾으려면 master
다음을 수행하십시오.
git rev-parse --abbrev-ref master@{upstream}
# => origin/master
각 지점에 대한 정보를 인쇄하려면 다음과 같이 할 수 있습니다.
while read branch; do
upstream=$(git rev-parse --abbrev-ref $branch@{upstream} 2>/dev/null)
if [[ $? == 0 ]]; then
echo $branch tracks $upstream
else
echo $branch has no upstream configured
fi
done < <(git for-each-ref --format='%(refname:short)' refs/heads/*)
# Output:
# master tracks origin/master
# ...
이것은 refs와 config를 수동으로 파싱하는 것보다 깨끗합니다.
kubi의 대답에 대한 대안 .git/config
은 로컬 저장소 구성을 보여주는 파일을 보는 것입니다 .
cat .git/config
를 들어 현재의 지점, 여기에 두 가지 좋은 선택이 있습니다 :
% git rev-parse --abbrev-ref --symbolic-full-name @{u}
origin/mainline
또는
% git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)
origin/mainline
그 대답은 (잘못) 중복으로 표시된 약간 다른 질문에 대한 여기에도 있습니다 .
git for-each-ref --format='%(refname:short) <- %(upstream:short)' refs/heads
각 지역 지점에 대한 줄이 표시됩니다. 추적 분기는 다음과 같습니다.
master <- origin/master
추적되지 않는 항목은 다음과 같습니다.
test <-
현재 분기에 대해 git checkout
(w / o any branch) 라고 말할 수도 있습니다 . 현재 분기에 대한 추적 정보가있는 경우 표시하는 부작용이없는 작업입니다.
$ git checkout
Your branch is up-to-date with 'origin/master'.
이 별칭을 사용합니다.
git config --global alias.track '!f() { ([ $# -eq 2 ] && ( echo "Setting tracking for branch " $1 " -> " $2;git branch --set-upstream $1 $2; ) || ( git for-each-ref --format="local: %(refname:short) <--sync--> remote: %(upstream:short)" refs/heads && echo --Remotes && git remote -v)); }; f'
그때
git track
Olivier Refalo의 답변을 바탕으로
if [ $# -eq 2 ]
then
echo "Setting tracking for branch " $1 " -> " $2
git branch --set-upstream $1 $2
else
echo "-- Local --"
git for-each-ref --shell --format="[ %(upstream:short) != '' ] && echo -e '\t%(refname:short) <--> %(upstream:short)'" refs/heads | sh
echo "-- Remote --"
REMOTES=$(git remote -v)
if [ "$REMOTES" != '' ]
then
echo $REMOTES
fi
fi
트랙이 구성된 로컬 만 표시합니다.
Write it on a script called git-track on your path an you will get a git track command
A more elaborated version on https://github.com/albfan/git-showupstream
git config --get-regexp "branch\.$current_branch\.remote"
will give you the name of the remote that is being tracked
git config --get-regexp "branch\.$current_branch\.merge"
will give you the name of the remote branch that's being tracked.
You'll need to replace $current_branch with the name of your current branch. You can get that dynamically with git rev-parse --abbrev-ref HEAD
The following mini-script combines those things. Stick it in a file named git-tracking
, make it executable, and make sure it's in your path.
then you can say
$ git tracking
<current_branch_name>-><remote_repo_name>/<remote_branch_name>
note that the remote branch name can be different from your local branch name (although it usually isn't). For example:
$git tracking
xxx_xls_xslx_thing -> origin/totally_bogus
as you can see in the code the key to this is extracting the data from the git config. I just use sed to clear out the extraneous data.
#!/bin/sh
current_branch=$(git rev-parse --abbrev-ref HEAD)
remote=$(git config --get-regexp "branch\.$current_branch\.remote" | sed -e "s/^.* //")
remote_branch=$(git config --get-regexp "branch\.$current_branch\.merge" | \
sed -e "s/^.* //" -e "s/refs\/.*\///")
echo "$current_branch -> $remote/$remote_branch"
Here is a neat and simple one. Can check git remote -v
, which shows you all the origin and upstream of current branch.
'your programing' 카테고리의 다른 글
정수 배열을 올바르게 정렬하는 방법 (0) | 2020.09.29 |
---|---|
모듈을 어떻게 언로드 (다시로드)합니까? (0) | 2020.09.29 |
특정 파일을 통해 grep하지 않으려면 grep --exclude /-include 구문을 사용하십시오. (0) | 2020.09.29 |
인터페이스 대 기본 클래스 (0) | 2020.09.29 |
간단한 if-then-else 문을 한 줄에 넣기 (0) | 2020.09.29 |