git rewrite commit author

最近發現自己有些 Git Repository 的 Git Author name 用錯了 account

git commit history with author name
git commit history with author name
忘記了在 clone repo 既時候要用

git config user.name "sharechiwai"
git config user.email "MY_EMAIL"

要找些方法去改變舊 commit 上的 Author name
做了一會 research 之後終於找到了

解決方法: 我們可以執行以下 git command 去 update 整個 repository 上的 Author name, Author email, committer name 和 committer email

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='YOUR_GIT_NAME'; GIT_AUTHOR_EMAIL='YOUR_GIT_EMAIL'; GIT_COMMITTER_NAME='YOUR_GIT_NAME'; GIT_COMMITTER_EMAIL='YOUR_GIT_EMAIL';" HEAD

git commit rewrite author name
git commit rewrite author name
e.g.

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='sharechiwai'; GIT_AUTHOR_EMAIL='YOUR_GIT_EMAIL'; GIT_COMMITTER_NAME='sharechiwai'; GIT_COMMITTER_EMAIL='YOUR_GIT_EMAIL';" HEAD

git commit rewrite author name success
git commit rewrite author name

Hope you find it useful

Chi Yau
Chi Yau
Software Engineer

Interested on Learning new stuff and experience sharing