특정 커밋에 대해 커밋 저자를 변경하는 방법은 무엇입니까?
질문
나는 역사상 하나의 특정 커밋의 저자를 바꾸고 싶다.마지막 커밋이 아닙니다.
나는이 질문에 대해 알고 있습니다 - Git에서 저자의 저자를 어떻게 바꿀 수 있습니까?
그러나 나는 해시 또는 짧은 해시에 의한 커밋을 식별하는 곳에서 뭔가를 생각하고 있습니다.
답변
대화식 rebase 수정 해야하는 커밋이 필요합니다 (rebase -i
git commit --amend --author="Author Name <email@address.com>" --no-edit
예를 들어, 커밋 기록이 F로 F가있는 A-B-C-D-E-F이고 C와 D의 저자를 변경하려는 경우 ...
- Specify
git rebase -i B
(here is an example of what you will see after executing thegit rebase -i B
command)- if you need to edit
A
, usegit rebase -i --root
- if you need to edit
- Change the lines for both
C
andD
frompick
toedit
- Exit the editor (for vim, this would be pressing Esc and then typing
:wq
). - Once the rebase started, it would first pause at
C
- You would
git commit --amend --author="Author Name <email@address.com>"
- Then
git rebase --continue
- It would pause again at
D
- Then you would
git commit --amend --author="Author Name <email@address.com>"
again git rebase --continue
- The rebase would complete.
- Use
git push -f
to update your origin with the updated commits.
답변
이 질문에 대한 받아 들여진 답변은 대화 형 리베이스의 훌륭하게 영리한 사용이지만, 이후에 병합 된 분기에있게 된 분기에있게하는 저자를 바꾸려고하는 저자를 바꾸려고하는 것이 우리가 저자를 바꾸려고하는 경우 불행히도 충돌을 보여줍니다.지저분한 역사를 처리 할 때.
Git History를 다시 작성하기위한 환경 변수를 설정하고 조정할 수있는 스크립트를 실행하는 것에 대해 알 수 있으므로이 답변과 비슷한이 게시물을 기반으로 새로운 답변을 작성하고 있습니다.
다음은 링크 된 답변과 달리 테스트되고 작동합니다. 03F482D6이 우리가 대체하려고하는 저자의 저자의 커밋이고 42627Abe는 새로운 저자와의 커밋임을 주장합니다.
Checkout the commit we are trying to modify.
git checkout 03f482d6
Make the author change.
git commit --amend --author "New Author Name <New Author Email>"
이제 우리는 42627Abe로 가정 한 해시로 새로운 커밋을했습니다.
Checkout the original branch.
Replace the old commit with the new one locally.
git replace 03f482d6 42627abe
Rewrite all future commits based on the replacement.
git filter-branch -- --all
Remove the replacement for cleanliness.
git replace -d 03f482d6
Push the new history (only use --force if the below fails, and only after sanity checking with
git log
and/orgit diff
).git push --force-with-lease
4-5 대신에 새로운 커밋으로 리베즈를 할 수 있습니다.
git rebase -i 42627abe
답변
GitHub 문서에는 지점의 모든 커밋에 대한 커미터 정보를 대체하는 스크립트가 포함되어 있습니다 (이제는 이제는 이는 마지막 스냅 샷입니다).
변수 값을 변경 한 후 터미널에서 다음 스크립트를 실행하십시오. #! / bin / sh. Git 필터 - 분기 - env-filter ' old_email = "yourd-mail@example.com" " coxt_name = "올바른 이름" coxt_email = "your-correct-email@example.com" [ "$ git_committer_email"= "$ oold_email"인 경우] 그 다음에 내보내기 git_committer_name = "$ court_name" 내보내기 git_committer_email = "$ court_email" ...에 대한 것 "$ git_author_email"= "$ old_email"이라면] 그 다음에 내보내기 git_author_name = "$ court_name" 내보내기 git_author_email = "$ court_email" ...에 대한 것 '- 티그 - 이름 필터 고양이 - - - 브랜치 - 태그 수정 된 기록을 GitHub에 밀어 넣으십시오. git push --force - tags 원산지 'refs / heads / *'
또는 분기의 선택된 참조를 누르고 싶다면
```
git push --force --tags origin 'refs/heads/develop'
```
답변
이메일을 전역으로 설정하십시오. git config --global user.email example@email.com 이제 편집 필수없이 커밋 작성자를 재설정하십시오. Git Commit - amend --reset-author -no-edit.
답변
아래 명령을 사용하여 마지막 커밋의 저자를 변경할 수 있습니다.
git commit - amend --author = "저자 이름
그러나 하나 이상의 커밋 저자 이름을 변경하려는 경우 조금 까다 롭습니다.대화식 리베이 효소를 시작한 다음 편집으로 commits를 표시하고 하나씩 수정하고 완료하십시오.
Git Rebase -i로 리베이를 시작하십시오.이런 식으로 당신을 보여줄 것입니다.

선택 키워드를 변경하여 작성자 이름을 변경하려는 커밋에 대해 편집하십시오.

그런 다음 편집기를 닫습니다.초보자를 위해 히트 탈출을 취소 한 다음 유형을 입력하고 입력하십시오.
그런 다음 아무 일도 일어나지 않는 것처럼 당신의 터미널을 볼 수 있습니다.실제로 당신은 대화식 리베이스의 중간에 있습니다.이제 위의 명령을 사용하여 커밋의 작성자 이름을 수정할 때입니다.편집기가 다시 열립니다.Git Rebase - Continue로 rebase를 종료하고 계속하십시오.편집하려는 커밋 횟수에 대해 동일한 것을 반복하십시오.진행중인 리베이 효소를 얻지 못하면 대화식 리베이 효소가 완성되었는지 확인할 수 있습니다.메시지.
답변
연결된 질문의 답변은 좋은 답변이며 상황을 충당합니다 (다른 질문은 여러 커밋을 다시 작성하는 것이기 때문에 더 일반적입니다).
Git Filter-Branch를 시도하기위한 변명의 경우, 저자 이름 및 / 또는 작성자 전자 메일을 주어진 커밋에 다시 작성하는 스크립트를 썼습니다.
#!/bin/sh
#
# Change the author name and/or email of a single commit.
#
# change-author [-f] commit-to-change [branch-to-rewrite [new-name [new-email]]]
#
# If -f is supplied it is passed to "git filter-branch".
#
# If <branch-to-rewrite> is not provided or is empty HEAD will be used.
# Use "--all" or a space separated list (e.g. "master next") to rewrite
# multiple branches.
#
# If <new-name> (or <new-email>) is not provided or is empty, the normal
# user.name (user.email) Git configuration value will be used.
#
force=''
if test "x$1" = "x-f"; then
force='-f'
shift
fi
die() {
printf '%s\n' "$@"
exit 128
}
targ="$(git rev-parse --verify "$1" 2>/dev/null)" || die "$1 is not a commit"
br="${2:-HEAD}"
TARG_COMMIT="$targ"
TARG_NAME="${3-}"
TARG_EMAIL="${4-}"
export TARG_COMMIT TARG_NAME TARG_EMAIL
filt='
if test "$GIT_COMMIT" = "$TARG_COMMIT"; then
if test -n "$TARG_EMAIL"; then
GIT_AUTHOR_EMAIL="$TARG_EMAIL"
export GIT_AUTHOR_EMAIL
else
unset GIT_AUTHOR_EMAIL
fi
if test -n "$TARG_NAME"; then
GIT_AUTHOR_NAME="$TARG_NAME"
export GIT_AUTHOR_NAME
else
unset GIT_AUTHOR_NAME
fi
fi
'
git filter-branch $force --env-filter "$filt" -- $br
출처:https://stackoverflow.com/questions/3042437/how-to-change-the-commit-author-for-one-specific-commit
최근댓글