Marcus Leon
Marcus Leon

Reputation: 56709

Git rerere file pattern?

Can git rerere be configured so it only remembers and applies merge resolutions on certain file patterns? Ie: just on the pattern pom.xml.

Upvotes: 3

Views: 210

Answers (1)

Jonathan.Brink
Jonathan.Brink

Reputation: 25453

This is a tough one, but I can think of a solution which involves invoking a script immediately after a merge operation (but before any manual resolving).

First off, the cache of conflict resolutions (.git/rr-cache) is stored by blob hash rather than by file path. There is nothing to indicate which file the resolutions actually came from, so I think hacking away at that directory would not be a viable solution.

This quote from maintainer Junio Hamano also hits on the fact that rerere is per-merge and not per-file:

There is no "I do not care if there are good resolutions remembered that do not have anything to do with the current merge, just remove all of them"---that is what "rm -fr .git/rr-cache" is for.

...which of course is not useful for you because selectively deleting files from .git/rr-cache is not well suited for automation in your use-case.

The feature to exploit may be the forget sub-command which takes a pathspec. The "forgetting" can only happen during the context of a merge however, which makes it fundamentally different than something like .gitignore which you can apply statically.

But, conceivably you could have a post-merge hook that invokes a script which:

Iterates over the conflicted files:

git diff --name-only --diff-filter=U

For every file that you want to "un-rerere", forget it:

git rerere forget -- path/to/file

...and restore the conflict:

git checkout -m path/to/file

Then, continue on with the merge per-usual leaving the rerere resolutions for the files you want remembered intact.

The list of files to have "rerere remembered" could be checked into the repository (perhaps in a file called .reremember) and queried from the script.

Upvotes: 0

Related Questions