gitgit-revertgit-rerere

How to prevent git from applying recorded changes during a git revert


So I did a git revert and resolved the conflicts which turned out to not be the correct resolution. Now the next time I do a git revert, to get to a stage where conflicts are still unresolved, git already applied previous resolution.

To summarize:

How do i make a fresh git revert such that I can resolve conflicts again the right way?


Solution

  • You have the rerere database enabled. You have to remove the incorrect resolutions from the database.

    As a first step, throw away the incorrectly reused resolution and start over:

    git reset --hard
    git revert SHA
    

    At this point, the incorrect resolutions are applied again. Let's fix that. First, remove the incorrect resolutions from the rerere database. You must do this per file:

    git rerere forget name/of/file
    

    Next, you resurrect the merge conflict and conflict markers:

    git checkout --merge name/of/file
    

    At this point, you can resolve the conflict in the correct way. Repeat for each file that has an incorrectly resolved conflict.

    After you have fixed all incorrect resolutions, complete the commit as usual. The corrected resolutions will be recorded in the rerere database.