141

I've read various things about git's rerere feature, and I'm considering enabling it.

The git rerere functionality is a bit of a hidden feature. The name stands for “reuse recorded resolution” and, as the name implies, it allows you to ask Git to remember how you’ve resolved a hunk conflict so that the next time it sees the same conflict, Git can resolve it for you automatically.

https://git-scm.com/book/en/v2/Git-Tools-Rerere

But I haven't seen anyone mention any possible problems that could arise while using rerere.

I have to assume there is a downside, or it would probably be enabled by default. So is there any downside to enabling rerere? What potential problems can it cause that would not otherwise occur?

2
  • When automatic rerere is enabled and it applies a previous resolution, does it display a message? If so, what does it look like? TIA! Commented Jun 19, 2014 at 1:27
  • 1
    @joeytwiddle, per this article, it would be of the form, Resolved 'index.html' using previous resolution.
    – user82216
    Commented Apr 8, 2018 at 9:59

5 Answers 5

91

If you do a merge incorrectly, then discard it, then do the "same" merge again, it will be incorrect again. You can forget a recorded resolution, though. From the documentation:

git rerere forget <pathspec>

This resets the conflict resolutions which rerere has recorded for the current conflict in <pathspec>.

Be careful to use it on specific paths; you don't want to blow away all of your recorded resolutions everywhere. (forget with no arguments has been deprecated to save you from doing this, unless you type git rerere forget . to explicitly request it.)

But if you don't think to do that, you could easily end up putting that incorrect merge into your history..

4
  • 19
    This is why rerere still leaves the files with conflicts marked as unmerged, so that you have to manually add them (hopefully after inspecting/testing them) before committing. You can always use git checkout -m <path> to check out the original conflicted version and redo the resolution if you have to.
    – Cascabel
    Commented Apr 2, 2011 at 6:15
  • 2
    That would make sense! Sounds like you need a new alias.
    – Cascabel
    Commented Apr 2, 2011 at 7:01
  • 8
    I think this is probably the main issue. Enabling rerere adds one more way for errors to sneak in unexpectedly. A merge that you abort (or rather undo by deleting it from the history) could still come back to haunt you later. Basically, it introduces a second history mechanism that is orthogonal to the actual history graph. Commented Apr 2, 2011 at 23:09
  • 3
    @RyanThompson Aborted merges don't affect rerere. (I often wish they did—I've sometimes aborted a merge because I set it up wrong, then needed to do the exact same resolutions when I set it up right.) As for deleting a merge from the history, why would you ever do that? Commented Feb 11, 2014 at 21:49
52

As J. C. Hamano mentions in his article "Fun with rerere" (my bold)

  • Rerere remembers how you chose to resolve the conflicted regions;
  • Rerere also remembers how you touched up outside the conflicted regions to adjust to semantic changes;
  • Rerere can reuse previous resolution even though you were merging two branches with different contents than the one you resolved earlier.

Even people who have been using rerere for a long time often fail to notice the last point.

So if you activate rerere on too broad a content, you might end up with surprising or confusing merge resolution because of the last point.


Another downside was rerere asking you for your pin for GPG signature (if you had activated commit.gpgSign).
This has been fixed with Git 2.38 (Q3 2022)

3
  • 21
    The conflicting hunks do still have to match; it's fairly difficult for it to give a false positive.
    – Cascabel
    Commented Apr 1, 2011 at 23:13
  • And there is git rerere gc to forget old resolutions. With shorter time range the probability of mishit is less.
    – gavenkoa
    Commented Mar 20, 2021 at 23:41
  • 4
    @gavenkoa True (git-scm.com/docs/git-rerere#Documentation/git-rerere.txt-emgcem): by default, unresolved conflicts older than 15 days and resolved conflicts older than 60 days are pruned.
    – VonC
    Commented Mar 20, 2021 at 23:52
8

I've got rerere globally enabled. I really haven't noticed any problems, and it usually seems to make my life easier.

3
  • 8
    Same here. No problems in 2+ years of usage. Commented Sep 14, 2012 at 11:09
  • 2
    @AndreyTarantsov any update after 12+ years of usage?
    – manish ma
    Commented May 14, 2023 at 19:07
  • 3
    @manishma I’m not Andrey, but I still love rerere. Commented May 15, 2023 at 17:54
5

I cherry picked a commit (in gitk) that only contained a binary file. Cherrypick failed due to conflict (which coming to think about it is natural) and I resolved the conflict keeping the cherry pick. I was surprised later to find in another rebased branch that my dlls did not behave - only to discover they were not carried into the rebase as (I speculate) automatic conflict resolution. So this is the only case I met (having rerere enabled) of running into counterintuitive (though I am sure perfectly consistent) behavior.

2
  • 1
    Cure: git rerere forget path/to/compiled/bin.dll Commented May 31, 2015 at 4:11
  • In the original case I got the conflict not on cherry picking but on rebasing but I don't think it makes a difference Commented May 31, 2015 at 15:42
1

According to this question and answer, Rerere doesn't record parts of the resolution that are not in the conflicting file. One instance where this might occur is during the refactoring of a file, wherein certain lines are extracted and moved to another file, and a conflicting commit subsequently alters those lines. The resolution in this scenario would involve making the changes in the new file.

Example

Initial state

file a:

const foo = [
    'line 1',
    'line 2',
    'line 3',
];
// ...
const str = foo.join("\n");

Refactoring

new file b:

const foo = [
    'line 1',
    'line 2',
    'line 3',
];

refactored file a:

// ...
const str = b.foo.join("\n")

Conflicting Change

change to a in another branch:

const foo = [
    'line 1',
    'line 2',
    'new line',
    'line 3',
];
// ...
const str = foo.join("\n");

Resolution

The resolution retains the refactored content in file a as is and adds the new line to file b. However, note that Rerere only reapplies the resolution to file a since it had conflicts during the initial resolution, whereas file b didn't encounter any conflicts initially.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.