背景

在工作中咱们常常会被要求应用特定的账号和邮箱提交代码,但有时git配置的谬误,导致提交了很多谬误的commit,push被拦挡。这时候咱们能够git指令来批改曾经提交的commit,来解决问题。

指令解说

  1. git log 查看commit id
  2. git rebase -i <最早commit> 从新设置基准线
  3. git commit --amend --author="Author Name mailto:email@address.com" --no-edit 来批改commit
  4. git rebase --continue 挪动到下个commit作为基准线

例子

如以后历史为 A-B-C(HEAD),我想批改B和C,这两个commit的作者。

  1. git rebase -i A

    • 如果想改A则应用git rebase -i --root
  2. B和C的commit,批改pick到edit。
  3. 退出编辑器。按ESC,输出:wq。保留批改。
  4. 当初你曾经开始能够批改,此时以后commit为B。
  5. git commit --amend --author="Author Name mailto:email@address.com" 批改B的提交。
  6. git rebase --continue 定位到C
  7. git commit --amend --author="Author Name mailto:email@address.com" 批改C的提交。
  8. 批改已实现。
  9. git push -f 提交代码,功败垂成。