关于git:Git修改commit作者和邮箱

5次阅读

共计 593 个字符,预计需要花费 2 分钟才能阅读完成。

背景

在工作中咱们常常会被要求应用特定的账号和邮箱提交代码,但有时 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 提交代码,功败垂成。
正文完
 0