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


答:一共分成两步

一. 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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM