Git修改提交信息

0

# 修改最近两次
git rebase -i HEAD~2
# pick改为edit
git commit --amend --reset-author
git rebase --continue
git push --force

# 指定ID
git rebase -i commit id
git rebase -i commit id~1
git commit --amend --author="name<mail@domain.com>" --no-edit
git rebase --continue
git push --force

如果修改数据太多或者太过久远使用下面脚本:

#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="acgist@qq.com"
CORRECT_NAME="acgist"
CORRECT_EMAIL="289547414@qq.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

# 多次执行删除目录:.git/refs/original
# 如果上面目录可以不用删除末尾添加参数:-f
# 强制推送远程仓库:git push origin --force --all
# 恢复:git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD