Git Tools – Rerere

trymas1 pts0 comments

Git - Rerere

Chapters ▾

1. Getting Started

1.1<br>About Version Control

1.2<br>A Short History of Git

1.3<br>What is Git?

1.4<br>The Command Line

1.5<br>Installing Git

1.6<br>First-Time Git Setup

1.7<br>Getting Help

1.8<br>Summary

2. Git Basics

2.1<br>Getting a Git Repository

2.2<br>Recording Changes to the Repository

2.3<br>Viewing the Commit History

2.4<br>Undoing Things

2.5<br>Working with Remotes

2.6<br>Tagging

2.7<br>Git Aliases

2.8<br>Summary

3. Git Branching

3.1<br>Branches in a Nutshell

3.2<br>Basic Branching and Merging

3.3<br>Branch Management

3.4<br>Branching Workflows

3.5<br>Remote Branches

3.6<br>Rebasing

3.7<br>Summary

4. Git on the Server

4.1<br>The Protocols

4.2<br>Getting Git on a Server

4.3<br>Generating Your SSH Public Key

4.4<br>Setting Up the Server

4.5<br>Git Daemon

4.6<br>Smart HTTP

4.7<br>GitWeb

4.8<br>GitLab

4.9<br>Third Party Hosted Options

4.10<br>Summary

5. Distributed Git

5.1<br>Distributed Workflows

5.2<br>Contributing to a Project

5.3<br>Maintaining a Project

5.4<br>Summary

6. GitHub

6.1<br>Account Setup and Configuration

6.2<br>Contributing to a Project

6.3<br>Maintaining a Project

6.4<br>Managing an organization

6.5<br>Scripting GitHub

6.6<br>Summary

7. Git Tools

7.1<br>Revision Selection

7.2<br>Interactive Staging

7.3<br>Stashing and Cleaning

7.4<br>Signing Your Work

7.5<br>Searching

7.6<br>Rewriting History

7.7<br>Reset Demystified

7.8<br>Advanced Merging

7.9<br>Rerere

7.10<br>Debugging with Git

7.11<br>Submodules

7.12<br>Bundling

7.13<br>Replace

7.14<br>Credential Storage

7.15<br>Summary

8. Customizing Git

8.1<br>Git Configuration

8.2<br>Git Attributes

8.3<br>Git Hooks

8.4<br>An Example Git-Enforced Policy

8.5<br>Summary

9. Git and Other Systems

9.1<br>Git as a Client

9.2<br>Migrating to Git

9.3<br>Summary

10. Git Internals

10.1<br>Plumbing and Porcelain

10.2<br>Git Objects

10.3<br>Git References

10.4<br>Packfiles

10.5<br>The Refspec

10.6<br>Transfer Protocols

10.7<br>Maintenance and Data Recovery

10.8<br>Environment Variables

10.9<br>Summary

A1. Appendix A: Git in Other Environments

A1.1<br>Graphical Interfaces

A1.2<br>Git in Visual Studio

A1.3<br>Git in Visual Studio Code

A1.4<br>Git in IntelliJ / PyCharm / WebStorm / PhpStorm / RubyMine

A1.5<br>Git in Sublime Text

A1.6<br>Git in Bash

A1.7<br>Git in Zsh

A1.8<br>Git in PowerShell

A1.9<br>Summary

A2. Appendix B: Embedding Git in your Applications

A2.1<br>Command-line Git

A2.2<br>Libgit2

A2.3<br>JGit

A2.4<br>go-git

A2.5<br>Dulwich

A3. Appendix C: Git Commands

A3.1<br>Setup and Config

A3.2<br>Getting and Creating Projects

A3.3<br>Basic Snapshotting

A3.4<br>Branching and Merging

A3.5<br>Sharing and Updating Projects

A3.6<br>Inspection and Comparison

A3.7<br>Debugging

A3.8<br>Patching

A3.9<br>Email

A3.10<br>External Systems

A3.11<br>Administration

A3.12<br>Plumbing Commands

2nd Edition

7.9 Git Tools - Rerere

Rerere

The git rerere functionality is a bit of a hidden feature.<br>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.

There are a number of scenarios in which this functionality might be really handy.<br>One of the examples that is mentioned in the documentation is when you want to make sure a long-lived topic branch will ultimately merge cleanly, but you don’t want to have a bunch of intermediate merge commits cluttering up your commit history.<br>With rerere enabled, you can attempt the occasional merge, resolve the conflicts, then back out of the merge.<br>If you do this continuously, then the final merge should be easy because rerere can just do everything for you automatically.

This same tactic can be used if you want to keep a branch rebased so you don’t have to deal with the same rebasing conflicts each time you do it.<br>Or if you want to take a branch that you merged and fixed a bunch of conflicts and then decide to rebase it instead — you likely won’t have to do all the same conflicts again.

Another application of rerere is where you merge a bunch of evolving topic branches together into a testable head occasionally, as the Git project itself often does.<br>If the tests fail, you can rewind the merges and re-do them without the topic branch that made the tests fail without having to re-resolve the conflicts again.

To enable rerere functionality, you simply have to run this config setting:

$ git config --global rerere.enabled true

You can also turn it on by creating the .git/rr-cache directory in a specific repository, but the config setting is clearer and enables that feature globally for you.

Now let’s see a simple example, similar to our previous one.<br>Let’s say we have a file named hello.rb that looks like this:

#! /usr/bin/env ruby

def hello<br>puts 'hello world'<br>end

In one branch we change the word “hello” to “hola”, then in another branch we change the “world” to “mundo”, just like before.

Figure 160. Two branches changing the same part of the same file differently

When we merge the two branches together, we’ll get a merge conflict:

$ git merge i18n-world<br>Auto-merging hello.rb<br>CONFLICT (content): Merge...

rerere summary merge branch getting branches

Related Articles