Training git rerere
One advanced git feature is
git rerere, which helps with resolving the same merge conflicts multiple times, e.g. when regularly rebasing a branch. In short, when activated, git will record the conflicts before and after you manually resolve them. During future conflicts, it will automatically try to apply the recorded resolutions, so you don’t have to manually resolve the same conflict again, which is error-prone.
The feature can be enabled for a repository with
git config rerere.enabled true
When you first enable it on an existing repository which contains merge conflict resolutions, git rerere won’t automatically know about them because they haven’t been recorded while the feature is active.
Luckily there is an useful
rerere-train.sh script to automatically record past merge conflict resolutions into its database. On Ubuntu this is also included in the
git apt package at
/usr/share/doc/git/contrib/rerere-train.sh (although without the execute bit set).
After enabling git rerere, you can use the script to learn conflict resolutions from a range of commits
commit1..commit2 using the following command:
bash /usr/share/doc/git/contrib/rerere-train.sh commit1..commit2
If only one commit is given instead of a range, the script will train git rerere on the entire history back to the initial commit, which is probably undesired and useless.