5

I want to undo a single pushed commit that's "in the middle" of the git history, i.e. it's not the most recent commit.

Should I use git revert <commit hash>, git cherry-pick, or something else?

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
Antonio
  • 97
  • 5

2 Answers2

6

Use git revert <commit hash>. git cherry-pick is for when you want to redo a commit.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
2

You should use git revert <SHA> to do this. That will ensure that the changes you make are tracked, and if any other developer now pulls in the branch, he will not face issues/conflicts because the histories were out of sync.

On the other hand, using git cherry-pick is basically used to pick a commit, and apply it in a different branch, and so won't work here.

You could also have used interactive rebase to undo/squash your changes, but that can very possibly result in conflicts on other developer's machines.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186