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