Undo a commit in the middle of a Git history

I want to undo a single pushed commit that is "in the middle" of the git history, i.e. not the last commit.

Should I use git revert <commit hash>

, git cherry-pick

or something else?

+3


source to share


2 answers


Use git revert <commit hash>

. git cherry-pick

to repeat the commit.



+3


source


You must use git revert <SHA>

for this. This will ensure that the changes you make are tracked and if some other developer now pulls into the branch, they won't run into problems / conflicts because the stories are out of sync.

On the other hand, the usage git cherry-pick

is mostly used to select a commit and apply it on another branch and therefore won't work here.



You can also use interactive redirects to undo / redirect your changes, but this can lead to conflicts on other development machines.

+2


source







All Articles