修改 Git commit 的作者
原文由 Ellie Huxtable 于 發布,訂閱此部落格
還滿常不小心用錯 email 來 commit 的。我有幾個 email 會依不同用途分開使用,所以確保用對是很重要的 :)
修改最新一筆 commit 的作者
這個最簡單!
git commit --amend --author="Example Name <[email protected]>"使用互動式 rebase
git rebase -i加上你想要的基底- 把想修改的 commit 標記為
edit,而不是pick - 執行
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
我第一次是在 split git repo 裡提到 git-filter-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]"
'隨機一篇部落格
留言
登入後參與討論