You have a branch that conflicts with
master in small but numerous occasions. Manually fixing each would be repetitive. Even running
git checkout --theirs -- [filename] on each would be repetitive.
We need several things here:
A way to get a list of all conflicted files
A way to interactively filter out the files we don't want (it's unlikely you know exactly which files have trivial diffs beforehand)
xargs to pass these into
A naive approach would be to use the output of
git diff. We use the
--no-pager option to
cat the output for use in pipes.
git --no-pager diff --name-only | fzf | xargs git checkout --theirs --
However, this does not distinguish between regular diffs and conflicts.
Looking at the docs, it seems like adding the
--check flag to
git diff does what we want. However,
--check also flags whitespace markers for some reason, which can add noise, and it adds text after the filename, which must be split out (and I'm bad at
--diff-filter option is more promising. With
--diff-filter=U, we only list unmerged files, and when rebasing, only conflicts are shown.
So, our final solution is:
git --no-pager diff --name-only --diff-filter=U | fzf | xargs git checkout --theirs --
There's an interesting file picker tool from Facebook called PathPicker. Rather than operating on lines
fpp parses input and extracts path-like entities. This doesn't filter out non-conflicted diffs, but at least the filenames will be visually organized and sectioned like they are from
git status. Thus, our command becomes:
git status | fpp
This approach relies more heavily on a UI, but is simpler.
When you are sure that all conflicts are trivial, there is a blunter, simpler solution:
git rebase --abortgit rebase -Xtheirs origin/master
While figuring this out, I also stumbled across
git checkout --conflict, which resets merge conflict markers in case you made a mistake and want to start the resolution from scratch.