NaraLuwan / NaraLuwan.github.io

Personal Website
https://hechao.me
1 stars 0 forks source link

批量订正已推送的commit记录的用户名和邮箱 #2

Open NaraLuwan opened 5 years ago

NaraLuwan commented 5 years ago

!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="old-email@example.com" CORRECT_NAME="Correct Name" CORRECT_EMAIL="correct-email@example.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags

NaraLuwan commented 5 years ago

官网指南:https://help.github.com/articles/changing-author-info/

NaraLuwan commented 5 years ago

git filter-branch -f --env-filter \ "GIT_AUTHOR_NAME='Newname'; GIT_AUTHOR_EMAIL='newemail'; \ GIT_COMMITTER_NAME='committed-name'; GIT_COMMITTER_EMAIL='committed-email';" HEAD

HEAD可以替换成 HEAD~3...HEAD 这样就可以指定哪几次提交替换