0

Simple question and I don't really have code to show sorry.

In git is it possible or whats the best way to revert a commit after I have more commit after the commit I would like to revert.

If I have commits 1,2,3,4 and 5 and I want to revert commit 3 is there a way to revert commit 3.

I know how to revert a commit with git revert 98b8ad2df210a6f05a2f but if I do this I'm getting conflicts.

I want to revert commit 3 but still have the commits 4 and 5.

Do you need to revert 4,5 and then 3 and then add back 4 and 5

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
lomine
  • 873
  • 5
  • 20
  • 36
  • I thought I could just revert commit 3 but I get an error message `CONFLICT (content): Merge conflict in src/App.tsx error: could not revert 3e99509... commit three hint: after resolving the conflicts, mark the corrected paths hint: with 'git add ' or 'git rm ' hint: and commit the result with 'git commit'` – lomine Feb 13 '22 at 11:35
  • That may well be the case. Reverting a commit creates a **new commit** which undoes the changes from the reverted commit. Presumably the location of those changes has been changed again by the commits after it. This produces a conflict, which is git asking you to specify which change takes priority. [Here is some advice on resolving merge conflicts](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line) – Tom W Feb 13 '22 at 11:51

1 Answers1

0

If there's a conflict, there's a conflict. You have to resolve the conflict. Undoing 5, 4 and 3 and then redoing 4 and 5 would result in the same (or simlar) conflicts.

Bite the bullet, resolve the conflicts, commit the resolution. Move on.

knittl
  • 246,190
  • 53
  • 318
  • 364