Listen to this Post
Marre de résoudre 10 fois le même conflit dans git ? Cette option méconnue va vous changer la vie 👇️
La fonctionnalité, c’est `git rerere` pour « REuse REcorded REsolution ». Quand c’est activé, git va mémoriser tous les conflits qu’il rencontre, enregistrer votre résolution du conflit, et automatiquement la réappliquer s’il retrouve le même conflit.
Vous rebasez plusieurs fois une branche ? Pas besoin de résoudre le même conflit.
Vous avez une branche qui va vivre longtemps ? Mergez `develop` dedans régulièrement, résolvez les conflits et annulez le commit de merge. La résolution sera utilisée au moment du merge final.
Le plus beau ?
Vous n’avez rien à faire.
Activez simplement l’option `rerere.enabled` et git va faire son taf tout seul. S’il peut appliquer une résolution il le fera, sinon il vous laisse faire comme d’habitude.
La commande magique 👉️ git config --global rerere.enabled true. De rien.
You Should Know:
1. Enable `git rerere` Globally:
git config --global rerere.enabled true
2. Check if `rerere` is Enabled:
git config --get rerere.enabled
3. Manually Record a Conflict Resolution:
- Resolve the conflict manually.
- Stage the resolved files.
- Commit the changes.
- Git will automatically record the resolution for future use.
4. Reuse Recorded Resolutions:
- When the same conflict occurs again, Git will automatically apply the recorded resolution.
5. View Recorded Resolutions:
git rerere diff
6. Clear Recorded Resolutions:
git rerere clear
7. Rebase with `rerere`:
git rebase --rerere-autoupdate <branch>
8. Merge with `rerere`:
git merge --rerere-autoupdate <branch>
9. Check Status of `rerere`:
git rerere status
10. Disable `rerere`:
git config --global rerere.enabled false
What Undercode Say:
Git’s `rerere` (Reuse Recorded Resolution) is a powerful yet underutilized feature that can save developers significant time and effort when dealing with repetitive merge conflicts. By enabling rerere, you allow Git to remember how you resolved conflicts and automatically apply those resolutions in the future. This is particularly useful in long-lived branches or when performing frequent rebases.
To maximize the benefits of rerere, consider integrating it into your regular Git workflow. Regularly merge or rebase your feature branches with the main branch, resolve conflicts, and let Git record those resolutions. This practice ensures that when you finally merge your feature branch, most conflicts will be resolved automatically.
Additionally, combining `rerere` with other Git commands like `rebase` and `merge` can further streamline your workflow. For instance, using `git rebase –rerere-autoupdate` can help maintain a clean commit history while minimizing manual conflict resolution.
In conclusion, `git rerere` is a game-changer for developers who frequently deal with merge conflicts. By leveraging this feature, you can focus more on writing code and less on resolving repetitive conflicts.
Related Commands:
- Linux:
git log --oneline git diff <commit1> <commit2> git stash git stash apply
-
Windows:
git status git add . git commit -m "Your commit message" git push origin <branch>
For more detailed information on git rerere, you can refer to the official Git documentation: Git Rerere Documentation.
References:
Reported By: Benoitaverty Marre – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅



