programing

Git 브랜치 크리에이터 찾기

stoneblock 2023. 7. 8. 10:32

Git 브랜치 크리에이터 찾기

저는 누가 지점을 만들었는지 알고 싶습니다.

다음과 같은 기능을 사용할 수 있습니다.

git branch -a | xargs -L 1 bash -c 'echo "$1 `git log --pretty=format:"%H %an" $1^..$1`"' _

그러나 분기를 만든 사용자가 아니라 분기당 마지막 커미터를 반환합니다.

작성자별 원격 Git 분기를 커밋 날짜별로 정렬하여 나열합니다.

git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate

분기는 커밋 포인터에 불과합니다.따라서 "누가 나를 창조했는가"와 같은 메타데이터를 추적하지 않습니다.직접 보세요.해라cat .git/refs/heads/<branch>저장소에 있습니다.

저장소에서 이 정보를 추적하려면 지점 설명을 확인하십시오.임의 메타데이터를 최소한 로컬로 분기에 연결할 수 있습니다.

또한 DarVar의 아래 답변은 이 정보를 얻을 수 있는 매우 현명한 방법입니다.

다음을 사용하여 이전 답변을 수정했습니다.--sort플래그를 지정하고 일부 색상/포맷을 추가했습니다.

git for-each-ref --format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p)    %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=authordate refs/remotes

DarVar의 답변에 추가:

git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n | awk '{print $7 $8}'

추신: 우리는 AWK를 사용하여 저자와 원격지를 예쁘게 인쇄했습니다.

로컬 리포지토리에 분기를 만든 사용자는 다음을 통해 확인할 수 있습니다.

git reflog --format=full

출력 예:

commit e1dd940
Reflog: HEAD@{0} (a <a@none>)
Reflog message: checkout: moving from master to b2
Author: b <b.none>
Commit: b <b.none>
(...)

그러나 일반적으로 사용자가 브랜치를 생성하는 로컬 리포지토리에서만 사용할 수 있기 때문에 이 방법은 유용하지 않을 수 있습니다.

정보는 ./.git/logs/refs/heads/branch에 저장됩니다.내용 예:

0000000000000000000000000000000000000000 e1dd9409c4ba60c28ad9e7e8a4b4c5ed783ba69b a <a@none> 1438788420 +0200   branch: Created from HEAD

이 예제의 마지막 커밋은 사용자 "b"에서 수행한 것이며 분기 "b2"는 사용자 "a"에서 생성된 것입니다.사용자 이름을 변경하면 gitreflog가 로그의 정보를 가져오고 로컬 사용자를 사용하지 않는지 확인할 수 있습니다.

저는 그 로컬 로그 정보를 중앙 저장소로 전송할 가능성이 있는지 모르겠습니다.

git for-each-ref --format='%(authorname) %09 -%(refname)' | sort

우리는 저자 이름을 바탕으로 알아낼 수 있습니다.

git for-each-ref --format='%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)' refs/remotes/ --sort=authorname DESC

가정:

  1. 가지가 만들어졌습니다.master
  2. 에 병합되지 않았습니다.master아직

 git log --format="%ae %an" master..<HERE_COMES_THE_BRANCH_NAME> | tail -1

이것이 전적으로 질문의 범위가 아니라는 것을 알지만, 특정 작성자의 커밋만 필터링할 필요가 있다면 언제든지 grep에 파이프를 연결할 수 있습니다 :)

# lists all commits in chronological order that
# belong to the github account with
# username `MY_GITHUB_USERNAME` (obviously you
# would want to replace that with your github username,
# or the username you are trying to filter by)


git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -committerdate | grep 'MY_GITHUB_USERNAME'

해피 코딩! :)

경고!

이러한 명령은 분기가 가리키는 커밋 데이터를 표시하므로 커밋 작성자는 분기 작성자와 다를 수 있습니다.Git은 지점 생성자를 저장하지 않고 커밋 하나만 저장합니다.

Azure Devops를 사용하는 경우 REST API를 사용하여 이 정보를 검색할 수 있습니다.

$baseAzdoURI/_apis/git/repositories/$repositoryName/refs

반환된 json 배열 내부에는 작성자 이름이 [collectionElement] 내부에 있습니다.크리에이터.표시 이름

전에

        {
        "name": "refs/heads/branchname",
        "objectId": "GUID",
        "creator": {
            "displayName": **"John Deere"**,
            "url": "$baseAzdoURI/_apis/Identities/GUID",
            "_links": {
                "avatar": {
                    "href": "$baseAzdoURI/_apis/GraphProfile/MemberAvatars/BASE64STUFF"
                }
            },
            "id": "guid",
            "uniqueName": "DOMAIN\\USERNAME",
            "imageUrl": "$baseAzdoURI/_api/_common/identityImage?id=guid",
            "descriptor": "BASE64STUFF"
        },
        "url": "$baseAzdoURI/GUID/_apis/git/repositories/GUID/refs?filter=heads%2FBRANCHNAME"
    },

참조: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/refs/list?view=azure-devops-rest-7.0

제가 알기로는 당신이 지점만 만든 사람인지 알 수 있을 것 같습니다.이는 .git/ref/heads/<branch>의 첫 번째 행으로 표시됩니다."Created from HEAD"로 끝나는 경우 작성자가 됩니다.

DESC를 찾는 사람들을 위해...이것은 효과가 있는 것 같습니다.--sort=-

포맷에 적합합니다. 이것은 처음입니다... 제 눈은 충혈되어 있습니다.

git for-each-ref --format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p)    %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=-authordate refs/remotes

추가 참조: https://stackoverflow.com/a/5188364/10643471

언급URL : https://stackoverflow.com/questions/12055198/find-out-a-git-branch-creator