깃의 문제점 중 하나는 자동 포매터(ex. eslint, prettier, black, checkstyle, ...)를 썼을 때 blame으로 내역을 보기가 힘들어 진다는 겁니다. git blame 히스토리를 유지하기 위해 틀어진 코드 스타일을 수정하지 않는, 어떻게 보면 주객전도된 상황도 많이 나왔습니다.

git 2.23 버전부터는 blame에서 특정 리비전을 제외할 수 있게 되었습니다.

 

--ignore-rev <rev>
    Ignore changes made by the revision when assigning blame, as if the change never happened. Lines that were changed or added by an ignored commit will be blamed on the previous commit that changed that line or nearby lines. This option may be specified multiple times to ignore more than one revision. If the blame.markIgnoredLines config option is set, then lines that were changed by an ignored commit and attributed to another commit will be marked with a ? in the blame output. If the blame.markUnblamableLines config option is set, then those lines touched by an ignored commit that we could not attribute to another revision are marked with a *.

--ignore-revs-file <file>
    Ignore revisions listed in file, which must be in the same format as an fsck.skipList. This option may be repeated, and these files will be processed after any files specified with the blame.ignoreRevsFile config option. An empty file name, "", will clear the list of revs from previously processed files.

git blame 옵션 --ignore-rev로는 특정 리비전 하나를, --ignore-revs-file는 여러 리비전을 제외할 수 있습니다.

 

https://github.com/electron/electron/blame/main/lib/browser/ipc-main-impl.ts

깃허브에서도 지원하고 있습니다.

 

설정

git config --local blame.ignoreRevsFile .git-blame-ignore-revs

깃 설정에서 기본 ignore rev file의 이름을 .git-blame-ignore-revs로 설정합니다. 꼭 이 파일명일 필요는 없는데 깃허브에서는 이 파일명만 되는 것 같으니 대세를 따릅시다

fatal: could not open object name list: .git-blame-ignore-revs

(⚠️ 주의: global로 설정하면 모든 리파지토리가 .git-blame-ignore-revs 파일을 갖고 있어야 git blame이 동작하니 local 설정 추천)

 

# Atom --> Electron rename
d9321f4df751fa32813fab1b6387bbd61bd681d0
34c4c8d5088fa183f56baea28809de6f2a427e02
# Enable JS Semicolons
5d657dece4102e5e5304d42e8004b6ad64c0fcda

.git-blame-ignore-revs 파일을 만들고 제외할 리비전을 쭉 써주면 끝입니다

주석은 #으로 쓸 수 있습니다

 

추가 옵션

# Mark any lines that have had a commit skipped using --ignore-rev with a `?`
git config --global blame.markIgnoredLines true

# Mark any lines that were added in a skipped commit and can not be attributed with a `*`
git config --global blame.markUnblamableLines true

--ignore-rev 옵션이 두개 있는데 필요하다면 설정하세요

  • blame.markIgnoredLines: 해당 라인에 skip된 커밋이 있다면 맨 앞에 ? 표시
  • blame.markUnblamableLines: skip된 커밋을 빼면 부모 커밋을 찾을 수 없는 경우 맨 앞에 * 표시

 

Reference

- https://git-scm.com/docs/git-blame#Documentation/git-blame.txt

- https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view

반응형