git rebase 修改多个提交信息

git rebase 修改多个提交信息

笔记本借给同事用了一段时间,他配置了全局user.nameuser.email,结果我提交的好多信息作者都是他,为了不给其他同事造成困扰,需要修改下这些提交的作者信息。

有两种方案选择修改哪些提交:

1
2
3
4
5
# 距当前提交的n个提交
git rebase -i HEAD~n

# 从当前提交到指定commit的提交
git rebase -i xxxxxx

输入完毕指令后会显示如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
pick ac0fcc6 add file1
pick a0cbfbe add file2
pick 16ee6eb add file3

# Rebase d57f11f..16ee6eb onto d57f11f (3 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell

将需要修改的提交前面的pico改为e或者edit然后保存。

执行修改作者指令,然后继续。

1
2
git commit --amend --author "yourname <yourname@example.com>"
git rebase --continue

修复完成,推送到远端

1
git push origin dev --force-with-lease

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!