Git rerere, short for "reuse recorded resolution," is a feature that allows Git to remember how you resolved merge conflicts in the past and reuse the same resolution for similar conflicts in the future. Here’s how to use it:
Enable Git rerere: You can enable Git rerere by running the following command:
git config --global rerere.enabled true
This command tells Git to start recording merge resolutions in the .git/rr-cache directory.
Resolve a merge conflict: When you encounter a merge conflict, resolve it as you normally would using your preferred merge tool. Git rerere will automatically record your resolution and save it in the .git/rr-cache directory.
Test Git rerere: To test Git rerere, you can intentionally create a merge conflict and resolve it using the same resolution as before. Git rerere will automatically reuse the recorded resolution and apply it to the new conflict.
$ git merge feature-branch
Auto-merging myfile.txt
CONFLICT (content): Merge conflict in myfile.txt
Resolved 'myfile.txt' using previous resolution.
Automatic merge went well; stopped before committing as requested
In this example, Git rerere automatically resolved the merge conflict in myfile.txt using a previously recorded resolution.
Using Git rerere can save time and effort when dealing with recurring merge conflicts, but there are some potential risks to consider:
Misleading history: Rerere can reuse merge conflict resolutions, which may lead to a misleading history. For example, if a conflict resolution is incorrect, rerere may apply it to similar conflicts in the future, resulting in a history that appears correct but is actually wrong.
Confidential data: Rerere caches conflict resolutions in plain text, which may expose confidential data if the resolutions contain sensitive information.
Maintenance overhead: Rerere’s cache needs to be maintained over time to avoid stale or invalid resolutions, which can add overhead to the repository’s maintenance.
To mitigate these risks, it’s important to review rerere’s cache regularly and ensure that the recorded resolutions are correct and do not expose sensitive data. Additionally, rerere can be disabled on a per-repository basis by running the command git config rerere.enabled false.