如何还原多个 git commit?

A -> B -> C -> D -> HEAD

答案

A <-- B  <-- C <-- D                                               <-- master <-- HEAD
A <-- B  <-- C <-- D <-- [(BCD)^-1]                   <-- master <-- HEAD
$ git revert --no-commit D
$ git revert --no-commit C
$ git revert --no-commit B
$ git commit -m "the commit message"
$ git checkout -f A -- .
$ git commit -a
A <-- B  <-- C <-- D <-- A'                       <-- master <-- HEAD
$ git reset --hard A
$ git reset --soft @{1}  # (or ORIG_HEAD), which is D
$ git commit
git revert master~3..master
A <- B <- C <- D <- BCD' <- HEAD
git revert --no-commit HEAD~3..
# revert all commits from B to HEAD, inclusively
$ git revert --no-commit B..HEAD  
$ git commit -m 'message'
git reset --hard a
git reset --mixed d
git commit
git diff HEAD commit_sha_you_want_to_revert_to | git apply
git checkout <branch_name>
git reset --hard <commit Hash for A>
git push -f
git checkout testing
git reset --hard abc1234
git push -f
$ git checkout -f <target-commit> -- .
$ git diff --name-status --cached <target-commit>
$ git rm <filespec>[ <filespec> ...]
$ git commit -m 'revert to <target-commit>'
$git diff <target-commit> <current-commit>
for i in `git rev-list <first-commit-sha>^..<last-commit-sha>`; do git revert -n $i; done
for i in `git rev-list <first-commit-sha>^..<last-commit-sha>`; do git revert --no-edit -s $i; done
o---o---o---o---o---o--->    
fff eee ddd ccc bbb aaa
for i in `git rev-list eee^..bbb`; do git revert --no-edit -s $i; done
git revert HEAD
git revert HEAD~2
git revert HEAD~4
git rebase -i HEAD~3 # pick, squash, squash