Programing

git-log의 색상

lottogame 2020. 8. 16. 21:42
반응형

git-log의 색상


실행 git log --decorate --pretty=oneline하면 출력 (HEAD, refs/published/master, master)에 채색 과 같은 항목 이 있습니다.

또한 gitconfig에 다음이 있습니다.

[color "branch"]
    current = yellow reverse
    local = yellow
    remote = green

다음과 같은 사용자 지정 형식을 수행 할 때 이러한 색상을 어떻게 복제합니까?

git log --decorate --stat --graph --pretty=format:"%d %Cgreen%h%Creset (%ar - %Cred%an%Creset), %s%n"

자식 1.8.3 (5 월 (24), 2013)로, 당신이 사용할 수있는 %C(auto)장식 %d의 형식 문자열에 git log.

로부터 릴리스 노트 :

 * "git log --format" specifier learned %C(auto) token that tells Git
   to use color when interpolating %d (decoration), %h (short commit
   object name), etc. for terminal output.)

git log --decorate기본적으로 넣어 것입니다 :

  • 청록색의 HEAD
  • 붉은 외딴 가지
  • 녹색 태그

color.decorate구성을 통해 변경할 수 있습니다 .

그러나이 git log --format구체적으로 표시하는 방법은 제공하지 않습니다 HEAD 또는 리모컨 또는 지점 : 세 가지를 통해 표시됩니다 %d가능한 한 색상.


로 업데이트 할 수 있습니다 2013, 아래 언급 에 의해 Elad 샤 하르 (upvoted), 1.8.3 이벤트를 한 번 더 옵션을 이눔 :

git log –format이제 터미널 출력을 %C(auto)위해 %d(장식), %h(짧은 커밋 객체 이름) 등을 해결할 때 Git에게 색상을 사용하도록 지시 하는 토큰을 자랑합니다 .

Atlassian 블로그 게시물 에서는이 기능이 형식 ( git rebase, git count-objects) 및 색상 ( git branch -vv) 에 중점을 둔 다른 여러 기능의 일부라고 설명합니다.

이것은 출력이 터미널 1에 사용되지 않을 때 자동으로 색상을 비활성화하는 auto,reset1.8.2 이전 버전에 추가 되었습니다.

%C(auto,blue)Hello%C(auto,reset)

참고 : git 2.4+ (2015 년 2 분기)는 브랜치 이름 주변의 색상을 더 잘 재설정 할 것입니다.
참조 5ee8758을 투입 하여 (Junio C 하마노 gitster) :

log --decorate: 다음 항목에 "커밋"색상을 누출하지 마십시오.

" git log --decorate"에서 다음과 같은 커밋 헤더를 볼 수 있습니다.

commit ... (HEAD, jc/decorate-leaky-separator-color)

여기서 " commit ... ("는 color.diff.commit, " HEAD"in color.decorate.head, " ,"in color.diff.commit, 분기 이름에서 color.decorate.branch" )" 를 닫 습니다 color.diff.commit.

HEAD와 로컬 브랜치 이름을 본문 텍스트와 같은 색으로 칠하고 싶다면 (아마도 청록색과 초록색이 흑백 터미널에서 너무 희미해서 읽을 수 없기 때문일 것입니다), 다음과 같이 말하고 싶지 않을 것입니다.

[color "decorate"]
    head = black
    branch = black

왜냐하면 white-on-black 터미널에서 동일한 구성을 재사용 할 수 없기 때문입니다. 당신은 순진하게 기대할 것입니다

[color "decorate"]
    head = normal
branch = normal

하지만 안타깝게도 그렇지 않습니다. 장식 요소 사이의 여는 괄호 또는 쉼표와 동일한 색상으로
문자열 " HEAD"및 분기 이름을 그립니다 .
이는 코드가 "접두사"를 고유 한 색상으로 인쇄 한 후 색상 재설정을 잊어 버리기 때문입니다.


git 2.5 (2015 년 2 분기)에서 버그가 수정되었습니다.

참조 429ad20을 투입 하여 Junio C 하마노 ( gitster) 5 월 13 일 2015 년
(에 의해 합병 Junio C 하마노 - gitster-fd70780 커밋 2015 년 5 월 22 일)을

log: 장식 이름을 너무 일찍 줄이지 마십시오.

log --decorate현재 브랜치의 끝에 커밋을 보여주는 " "Git 2.4의 개선 사항 (예 : " HEAD -> master")은 --decorate = full과 함께 작동하지 않았습니다.


망할 놈의 2.9.x + (Q3 2016) 또 다른 버그가 해결됩니다 명예 color=auto를 들어%C(auto)


Git 2.10.2 (2016 년 10 월)는 커밋 82b83da (2016 년 9 월 29 일) 및 René Scharfe (``)의 커밋 c99ad27 (2016 년 9 월 17 일 )로 다른 버그를 수정했습니다 . (Merged by Junio ​​C Hamano -- in commit 76796d4 , 28 Oct 2016)
gitster

pretty: %C(auto)출력이 비어있는 경우 재설정 추가 방지

We emit an escape sequence for resetting color and attribute for %C(auto) to make sure automatic coloring is displayed as intended.
Stop doing that if the output strbuf is empty, i.e. when %C(auto) appears at the start of the format string, because then there is no need for a reset and we save a few bytes in the output.

pretty: let %C(auto) reset all attributes

Reset colors and attributes upon %C(auto) to enable full automatic control over them; otherwise attributes like bold or reverse could still be in effect from previous %C placeholders.


Parenthesize them:

%C(...): color specification, as described in color.branch.* config option

So %C(yellow reverse) would work.


The config option log.decorate can enable/disable default decorations in logs.

git config --global log.decorate full

Once that is done you can use color.decorate.* to play with the colors


Some may want to use this : %C(colorname) This doesn't need to change the color config.

Example : Coloring the author name in yellow

--pretty=format:"%C(yellow)%an%Creset"

Regular ANSI colors should work https://en.wikipedia.org/wiki/ANSI_escape_code

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

참고URL : https://stackoverflow.com/questions/5889878/color-in-git-log

반응형