본문 바로가기

Tool

[Git] 커밋한 사용자(Author) 변경하기

728x90

문제점

코드를 수정하고 Commit을 하였는데 Git에 설정된 작성자(Author)가 잘못되었습니다.

기존 Commit의 작성자를 변경하고 다시 Push하려고 합니다.

해결방법

먼저 수정하고자 하는 Commit의 바로 이전 Commit의 Hash값을 확인합니다.

그리고 해당 Commit으로 Rebase 합니다.

$ git rebase -i -r hash값

그러면 Commit에 대한 목록수정 화면이 나오며 맨 앞에 pick으로 설정되어있습니다.

이것을 수정하기 위하여 edit로 변경합니다.

edit c584719 Commit that I want to change an author

# Rebase ca26481..dcd219b onto ca26481 (5 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
#                    commit's log message, unless -C is used, in which case
#                    keep only this commit's message; -c is same as -C but
#                    opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
#         create a merge commit using the original merge commit's
#         message (or the oneline, if no original merge commit was

저장하고(vi의 경우 :wq 명령) Commit의 amend 기능을 활용해서 해당 커밋의 author 정보를 수정합니다.

$ git commit --amend --author="newUser <newUser@email.com>" --no-edit

다음 명령으로 Rebase를 종료합니다.

$ git rebase --continue

추가로 서버에 Push가 되어있다면 force 옵션으로 Commit을 덮어씁니다.

단독으로 사용하는 경우에는 무리가 없으나, 다수가 사용하는 Git의 경우에는 주의하시기 바랍니다.

$ git push -f https://github.com/test/test.git

 

반응형