git 修改历史提交人

准备

将 git 工程设置成 正确的提交人:

git config user.name "xxxx"
git config user.email "xxx@email.com"

修改最后一次提交人

git commit --amend --reset-author

如果想要修改历史,就需要通过 rebase 操作

选择性修改

  1. git rebase -i HEAD~N, 如 git rebase -i HEAD~5, 显示历史的前5个提交记录

在这里插入图片描述

  1. 将要修改的提交的 pick 改成 edit :

在这里插入图片描述

  1. :wq 保存退出
Stopped at eb8e529...  init jery
You can amend the commit now, with

  git commit --amend 

Once you are satisfied with your changes, run

  git rebase --continue
  1. git commit --amend --reset-author, 在操作页面,:wq 保存退出

  2. git rebase --continue 回到正常状态

  3. git rebase --abort 放弃本义修改

所有分支全部替换

git filter-branch --env-filter '
OLD_EMAIL="xxx"
CORRECT_NAME="xxxx"
CORRECT_EMAIL="xxx"
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

这个更绝, 一把把所有的分支历史名字就替换了

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐