開發需要,本地維護了多個用戶名和郵箱組合,今天提交代碼後,發現用戶名和郵箱錯了,由於是貢獻的開源代碼,必須改回來。
修改當前repo的用戶名和郵箱
git config user.name "example" git config user.email "example@163.com"
修改全局的用戶名和郵箱
git config --global user.name "example" git config --global user.email "example@163.com"
修改最近一次提交記錄的用戶名和郵箱
git commit --amend --author="userName <userEmail>"
修改歷史提交的用戶名和郵箱
git filter-branch –env-filter ‘
if [ “GIT_AUTHOR_NAME” = “oldName” ]
then
export GIT_AUTHOR_NAME=”newName”
export GIT_AUTHOR_EMAIL=”newEmail”
fi ‘ HEAD~3..HEAD
git filter-branch –env-filter ‘
if [ “GIT_COMMITTER_NAME” = “oldName” ]
then
export GIT_COMMITTER_NAME=”newName”
export GIT_COMMITTER_EMAIL=”newEmail”
fi ‘ HEAD~3..HEAD
如果提示:
Cannot create a new backup. A previous backup already exists in refs/original/ Force overwriting the backup with -f
可以加上-f,即git filter-branch -f –env-filter。
原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/259014.html