Amending the author of a Git commit

Ellie Huxtable

Git 커밋 작성자 수정하기

원문은 Ellie Huxtable님이 에 게재했습니다. 이 블로그 구독하기

커밋할 때 실수로 잘못된 이메일로 커밋하는 경우가 꽤 자주 있다. 용도별로 쓰고 싶은 이메일이 몇 개 있어서 정확하게 쓰는 게 중요하다 :)

마지막 커밋의 작성자 수정하기

이 방법은 정말 간단하다!

git commit --amend --author="Example Name <[email protected]>"

인터랙티브 리베이스 사용하기

  1. 원하는 베이스에서 git rebase -i 실행
  2. 수정하려는 커밋을 pick 대신 edit으로 표시
  3. git commit --amend --author="Example Name <[email protected]>" 실행 후 git rebase --continue 실행

filter-branch 사용하기

전체 히스토리를 필터링하기! 다만 조심해야 한다. filter-branch는 부주의하게 사용하면 문제가 생길 수 있다

git filter-branch -f --commit-filter '
      if [ "$GIT_AUTHOR_EMAIL" = "[email protected]" ];
      then
              GIT_AUTHOR_NAME="New Name";
              GIT_AUTHOR_EMAIL="[email protected]";
              git commit-tree "$@";
      else
              git commit-tree "$@";
      fi' HEAD

filter-repo 사용하기

git-filter-reposplit git repo 글에서 처음 언급한 적이 있는데, 여기에서도 유용하다. filter-branch보다 권장되지만 기본 Git 설치에는 포함되어 있지 않다.

다음 명령어로 설치한다

curl "https://raw.githubusercontent.com/newren/git-filter-repo/main/git-filter-repo" -o ~/.local/bin/git-filter-path

그런 다음 아래 방법 중 하나를 실행하면 된다

mailmap으로

이전 주소를 새 주소로 매핑하도록 mailmap을 설정했다면 다음을 실행하면 된다

git filter-repo --use-mailmap

mailmap 없이

그렇지 않다면 다음 방법이 잘 동작한다

git filter-repo --email-callback '
    return email if email != b"[email protected]" else b"[email protected]"
    '

이 글은 muse-spark-1.2-contributor 모델을 사용해 번역했습니다.

댓글