Reputation: 42090
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.
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?
Upvotes: 143
Views: 18087
Reputation: 111
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.
file a
:
const foo = [
'line 1',
'line 2',
'line 3',
];
// ...
const str = foo.join("\n");
new file b
:
const foo = [
'line 1',
'line 2',
'line 3',
];
refactored file a
:
// ...
const str = b.foo.join("\n")
change to a
in another branch:
const foo = [
'line 1',
'line 2',
'new line',
'line 3',
];
// ...
const str = foo.join("\n");
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.
Upvotes: 2
Reputation: 1329902
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)
Upvotes: 52
Reputation: 34086
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.
Upvotes: 5
Reputation: 22136
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..
Upvotes: 92
Reputation: 6337
I've got rerere globally enabled. I really haven't noticed any problems, and it usually seems to make my life easier.
Upvotes: 8