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?
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?
Use git revert <commit hash>
. git cherry-pick
is for when you want to redo a commit.
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.