背景
在工作中咱们常常会被要求应用特定的账号和邮箱提交代码,但有时git配置的谬误,导致提交了很多谬误的commit,push被拦挡。这时候咱们能够git指令来批改曾经提交的commit,来解决问题。
指令解说
- git log 查看commit id
- git rebase -i <最早commit> 从新设置基准线
- git commit --amend --author="Author Name mailto:email@address.com" --no-edit 来批改commit
- git rebase --continue 挪动到下个commit作为基准线
例子
如以后历史为 A-B-C(HEAD),我想批改B和C,这两个commit的作者。
git rebase -i A
- 如果想改A则应用git rebase -i --root
- B和C的commit,批改pick到edit。
- 退出编辑器。按ESC,输出:wq。保留批改。
- 当初你曾经开始能够批改,此时以后commit为B。
- git commit --amend --author="Author Name mailto:email@address.com" 批改B的提交。
- git rebase --continue 定位到C
- git commit --amend --author="Author Name mailto:email@address.com" 批改C的提交。
- 批改已实现。
- git push -f 提交代码,功败垂成。