git 合并提交历史

1,318 阅读1分钟
  1. git log 找到需要合并的提交记录,往前找一个提交记录的hash
commit 93ef401bd3736f4136cfdcbea0448bbe5a4fcb52 
Author: xx
Date:   Thu Jan 6 11:02:29 2022 +0800

    fix3

commit b37c4656470b193ea42c8e1b1787b06b94ba74fe
Author: xx
Date:   Thu Jan 6 11:01:24 2022 +0800

    fix2

commit 49fe6b7d85266ef969f32c23e92b33a5215b957d
Author: xx
Date:   Wed Jan 5 16:54:26 2022 +0800

    fix1

commit 4943e6a8147852a6a6882b0daacddb86d445b14b
Author: xx
Date:   Wed Jan 5 16:09:13 2022 +0800

    npe

如果要合并fix1,fix2,fix3记录,则往前找一个提交记录hash(4943e6a8147852a6a6882b0daacddb86d445b14b的前9位 4943e6a8)

  1. git rebase -i 4943e6a8
pick 49fe6b7 fix3
pick b37c465 fix2
pick 93ef401 fix1

修改后两个pick为squash,然后保存退出:wq

  1. 修改合并后的历史
# This is a combination of 3 commits.
# This is the 1st commit message:

fix3

# This is the commit message #2:

fix2

# This is the commit message #3:

fix1

将这三个记录删除改成

这是三次记录的合并

保存:wq 4. 强制推送到远端 git push --force