4

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
  • 67,326
  • 35
  • 140
  • 172
Antonio
  • 87
  • 5

2 Answers2

5

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

David Deutsch
  • 15,353
  • 4
  • 45
  • 52
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
  • 67,326
  • 35
  • 140
  • 172