1. 程式人生 > >git 如何revert指定範圍內的commit並且只生成一個新的commit?

git 如何revert指定範圍內的commit並且只生成一個新的commit?

範圍 nbsp 多個 revert com -i 使用 log rebase

答:一共分成兩步

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

git 如何revert指定範圍內的commit並且只生成一個新的commit?