zl程序教程

您现在的位置是:首页 >  工具

当前栏目

git 如何revert指定范围内的commit并且只生成一个新的commit?

Git 如何 一个 生成 指定 范围 并且 commit
2023-09-11 14:16:48 时间

答:一共分成两步

一. revert多个commit并生成多个新的commit

  git revert <old commit>^..<new commit>

二. 使用rebase将多个新的commit合并成一个commit

  git rebase -i <base commit>

 

举例:

$git log

111111111 yes

222222222 no

333333333 yes or no

4444444444 no or yes

 

第一步: 执行git revert -n 333333333^..111111111将会生成一个commit,并且commit log将会变成如下状态:

777777777 Revert "yes or no"

666666666 Revert "no"

555555555 Revert "yes"

111111111 yes

222222222 no

333333333 yes or no

4444444444 no or yes

 

第二步: 执行git rebase -i 111111111