git修改已提交记录中用户名和邮箱

478 阅读1分钟

使用git rebase实现

  1. 第一步 git rebase -i 'commit id' // 修改当前commit id后续的所有 git rebase -i --root // 从首次提交开始修改

  2. 第二步,类似如下信息,修改第一行的pick为edit,:wq保存

       pick e99899c init
       
       # Rebase e99899c onto 14fd414 (1 command)
       #
       # Commands:
       # p, pick <commit> = use commit
       # r, reword <commit> = use commit, but edit the commit message
       # e, edit <commit> = use commit, but stop for amending
       # s, squash <commit> = use commit, but meld into previous commit
       # f, fixup <commit> = like "squash", but discard this commit's log message
       # x, exec <command> = run command (the rest of the line) using shell
       # b, break = stop here (continue rebase later with 'git rebase --continue')
       # d, drop <commit> = remove commit
       # l, label <label> = label current HEAD with a name
       # t, reset <label> = reset HEAD to a label
       # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
       # .       create a merge commit using the original merge commit's
       # .       message (or the oneline, if no original merge commit was
       # .       specified). Use -c <commit> to reword the commit message.
       #
       # These lines can be re-ordered; they are executed from top to bottom.
       #
       # If you remove a line here THAT COMMIT WILL BE LOST.
  1. 会出现如下信息,如果需要调整信息,使用git commit --amend,不需要使用git rebase --continue继续下一个提交的处理。 Stopped at e99899c... init You can amend the commit now, with
        git commit --amend 
  Once you are satisfied with your changes, run
        git rebase --continue
  • git commit --amend --author="用户名 <邮箱>" --no-edit此条命令可以修改邮箱,如果不添加--no-edit,还可以修改提交信息。
  1. git rebase --continue继续下一个commit的处理,重复步骤3操作。