0

I have resolved the conflict on my branch in the wrong way. Now I would like to go back to the commit where it was showing a conflict. I tried reverting but it is asking me to resolve the conflict.

1
  • Your question subject line talks about reverting to a particular commit. This is not what git revert does: git revert means to back out some specific (possibly historical) commit. Think of it as meaning "back out" or "undo". To revert to a commit, there are several possibilities (as in answers so far). Commented Feb 3, 2021 at 6:37

2 Answers 2

2

The command git revert will make a new commit with the reverse content. So each line you have added will be removed on this new commit, and vice-versa.

If you wanna drop some commits of your history, you need to use the command "reset". It will delete your revert commit, and turn your repository back to the same status before.

  1. Use "git log", to see the commit id before the revert (when your repository was ok):

    git log

  2. Use "git reset" to delete all the commits after your selected commit id

    git reset --hard

Git reset will not remove new files. If you have it, will be necessary delete them manualy.

Sign up to request clarification or add additional context in comments.

Comments

1

You didn't explain what you did that generated this conflict. Let's say, though, that it was a merge. Then you need to use git log to find out the SHA number of the commit before the merge commit that was created by that merge. Then you say git reset --hard <SHA> with that SHA number.

This will undo everything, including the merge, to the point before you did the merge.

Now ask for the merge again, and this time, when the conflict happens, resolve it correctly.

Note, however, that you just follow those instructions, you will lose everything you have done since the merge, and you will lose it forever. If that is not acceptable, then you need to take more elaborate action.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.