As I understood, it is useful for the synchronization of projects through the saving of conflict resolution information, but it is not entirely clear to me how to use and configure it.
I want to configure for my continuous integration (CI) environment. Is it recommended do this?
Please don't mark a duplicate with this other question: Are there any downsides to enabling git rerere?. Because my doubt isn't related to "So is there any downside to enabling rerere?. What potential problems can it cause that would not otherwise occur?"
Instead of running one of the known merge tool programs, git mergetool can be customized to run an alternative program by specifying the command line to invoke in a configuration variable mergetool. <tool>. cmd . When git mergetool is invoked with this tool (either through the -t or --tool option or the merge.
You can run git rebase --skip to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included. It is very rare that you would choose this option. You can fix the conflict.
Rerere 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.
Instead, Git thinks of its data more like a series of snapshots of a miniature filesystem. With Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
However, git rerere will also tell you what it has recorded the pre-merge state for with git rerere status: And git rerere diff will show the current state of the resolution — what you started with to resolve and what you’ve resolved it to.
The DevOps design methodology has a good collection of tools and resources for the developer, including Git. Git is an open-source version control system often used for source code management. It features a plethora of commands and functions that make the developer’s job easier. That’s why today we’re here to discuss the Git rebase command.
git rerere
?As the documentation notes, rerere
stands for reuse recorded resolution.
That doesn't really explain what it is, though. It's worth adding first, here, that git rerere
itself—the command—is not something you have to run. It has just six subcommands: clear
, forget
, diff
, status
, remaining
, and gc
. None of these record or reuse a resolution—in fact, git rerere clear
and git rerere forget <path>
just discard some recorded resolutions. The gc
command is similar, but refers to ones that are old, rather than current ones.
Most of the work happens from the setting of rerere.enabled
(which makes Git run git rerere
, with no subcommand, for you, at the appropriate times). You can run git rerere
with no subcommands yourself, but this doesn't really do anything important since Git will do that on its own.
git config rerere.enabled true
Once you have set rerere.enabled
, when Git does a merge—any merge, including those from git am
and git rebase
and git cherry-pick
and so on, not just those from git merge
itself—and hits a conflict, Git will:
git commit
time) what you did to resolve them.There's a step missing here, which is why this is numbered starting at 2. Step 1 is:
If the recorded resolutions completely resolve the conflicts, steps 2-4 become redundant. Git may still run them all (I'm not sure that it does) to update the timestamps on the recorded resolutions.
Once you set rerere.enabled
, it's the act of merging itself that both creates the conflicts and (because it automatically runs git rerere
with no arguments) records them and then tries to re-use any existing recorded resolutions. It's the act of committing itself that records the final resolutions (because Git automatically runs git rerere
again for you). So it is all automatic—you just need to make sure, by running your own git diff
commands, that your previous re-used resolutions are correct. If not, just fix them files, add, and commit as usual, and Git will replace the recorded resolutions with the new ones.
Note that you must still git add
and git commit
! You should always inspect the merge results (and/or run tests)—though you should do this always, regardless of your rerere.enabled
setting.
As VonC points out in a comment, if you have existing merge conflict resolutions you did not record earlier, you can "train" the rerere database on those resolutions. There is a contributed script in the Git source to do this; it's also available on-line.
It makes no sense to enable rerere
for your CI environment, because your CI environment should never be resolving merge conflicts in the first place. Why do you think you would want it there?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With