-
commit log의 email 변경dev/Experience 2024. 9. 30. 22:50
커밋할 때 사용하는 이메일 주소를 터미널에서 확인하는 명령어는 다음과 같습니다.
git config --global user.email
전역 설정 확인
git config user.email
로컬 설정(특정 repository) 확인
문제 상황
gitKraken(Git GUI Client)를 사용해 log를 관리하는 과정에서,
Github primary email이 아닌 Organization의 회사 email을 등록하여 사용하고 있었습니다.
그런데 어느순간 git contributions를 확인해보니 commit log가 찍히고 있지를 않더라구요..
Git의 settings > access > emails에 회사 이메일을 등록해놓지 않았었기에 등록했지만 여전히 반영되지 않았습니다.
[GitHub Docs]Why are my contributions not showing up on my profile?를 보면,
"기여로 간주되는 요구 사항을 충족하는 커밋을 한 후, 기여가 표시되려면 최대 24시간이 걸릴 수 있습니다."
라고 표현하고 있습니다.
근데 저는 이걸 바로 반영하고 싶었습니다. 다음에 제가 이 것이 반영되었는지 확인하지 않을 것 같았거든요.
그 때문에 특정 이메일로 commit된 로그의 이메일 주소만을 바꾸는 것이 가능한지 알아보았습니다.
지금봤는데 년도를 왜 2023년으로 기입했을까요..? 해결 과정
특정 커밋의 이메일을 수동으로 변경할 수 있습니다.
interactive rebase
git rebase -i HEAD~n
n은 변경하고자 하는 commit의 개수입니다.
전역 commit email을 정상적으로 돌려놓은 마지막 commit을 포함하여 아래로 21개의 commit을 조작합니다.
commit log가 vim편집기로 열리게 됩니다. (i: input, w: write, q: quit)
Log들(여기서는 21개의 row)에 대하여 수정해야 하는 커밋의 pick을 모두 edit으로 수정합니다.
:%s/pick/emit/g
해당 명령어로 모든 워딩을 치환할 수 있습니다.
순서대로 다음의 명령어를 입력합니다.
git commit --amend --author="{name} <{email}>"
해당 명령어를 통해 commit message를 수정할 수 있는 파일이 열리게 됩니다.
이미 '--author'을 통해 목표로 했던 email의 수정은 이뤄졌으므로, ':q'로 파일을 닫은 후 리베이스를 계속 진행합니다.
git rebase --continue
이 행위를 원하는 commit의 수정 개수만큼 반복합니다. 🤨
각 커밋마다 수동으로 이메일을 변경해야 하므로, 자동화된 방법은 아닙니다.
모든 커밋을 수정한 후, 원격 저장소에 강제 푸시합니다.
git push --force
결과적으로 다음과같이 해결할 수 있게 되었습니다.
최초 commit의 시간대와 동일한 시간대로 contributions에 반영됩니다.
발생할 수 있는 문제
1) rebase가 진행 중인 상태에서 엎어버리고 git rebase로 재접근.
fatal: It seems that there is already a rebase-merge directory, and I wonder if you are in the middle of another rebase. If that is the case, please try git rebase (--continue | --abort | --skip) If that is not the case, please rm -fr ".git/rebase-merge" and run me again. I am stopping in case you still have something valuable there.
git rebase --abort
를 입력하여 진행 중인 rebase를 취소 후, 재진입 해야 한다.
2) detached HEAD (branch가 없는)상태에서 push를 시도.
fatal: You are not currently on a branch. To push the history leading to the current (detached HEAD) state now, use git push origin HEAD:<name-of-remote-branch>
git checkout -b new-branch-name
git push origin new-branch-name
현재 커밋에서 새 브랜치를 만든 후, 원격 저장소에 push할 수 있도록 한다.
3) 터미널 내 Github password 입력 시, Personal Access Token (PAT)를 사용하지 않는 경우.
remote: Please see
https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. fatal: Authentication failed forGithub > Settings > Developer settings > Personal access tokens > Generate new token > 일반적으로 repo
'dev > Experience' 카테고리의 다른 글
2024.09.27 프론트엔드 파이트 클럽 (4) 2024.09.27