0

I'm on branch feature and rebasing onto master and histories have diverged. In feature dozens of files have been deleted that have at the same time been modified on master. I'm sure I don't need these files anymore, so rebase, keeping what's on feature:

git rebase -Xtheirs master

It accepts all the changes I did on feature but still leaves conflicts for modified files from master that have been deleted on feature, reporting:

CONFLICT (modify/delete): some/file1 deleted in HEAD~3 and modified in master. Version master of some/file1 left in tree.

And

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add/rm <file>..." as appropriate to mark resolution)

        deleted by them: some/path/file1
        deleted by them: other/path/file2
        deleted by them: another/path/file3
        ...

And there's a gazillion of them. I have to run git rm some/path/file1 for each of them. Is there an easy way to list all the deleted by them files and pass them to git rm automagically?

Update: If you want to try it out, here's a very small sample GitHub repo with that situation. Clone and checkout feature, then try to rebase onto master.

git clone https://github.com/chhh/git-rebase-conflict-resolution
git checkout feature
git rebase -Xtheirs master
Dmitry Avtonomov
  • 8,747
  • 4
  • 32
  • 45
  • 2
    There may be an easier way than this, but: start with `git ls-files --stage`. Each file that is "deleted by them" has a stage 1 entry and a stage 2 entry but no stage 3 entry. Read through the list (with awk or python), find such names, pass them to `git rm` (perhaps via xargs). – torek May 09 '18 at 19:51
  • @torek thanks for the hint, that `git ls-files --stage` was what I was looking for! The final answer: `git ls-files --stage | awk -v stage=3 -v path=4 '$stage == 2 {print $path}' | xargs git rm` – Dmitry Avtonomov May 09 '18 at 22:02
  • Be careful with that command: files will exist in *all three* stages when there's a normal everyday conflict. (Your `-Xtheirs` means there won't be any such conflicts, but if anyone tries to generalize that awk command, it may be painful.) – torek May 09 '18 at 22:05
  • The assumption here was that it's a rather common situation when you're the only one using a repo. You commit from machines having forgotten to pull first, and then you're sure that you only want stuff from the feature branch and don't care about the conflicts. Here's a sample repo of that situation: https://github.com/chhh/git-rebase-conflict-resolution – Dmitry Avtonomov May 09 '18 at 22:14

2 Answers2

0

TL;DR; oneliner:

git ls-files --stage | awk -v stage=3 -v path=4 '$stage == 2 {print $path}' | xargs git rm


Answering my own question, thanks to the comment to the original question by @torek.

git ls-files --stage will list the deleted by them files as having stage == 2.
Thus, using awk and xargs, the full one liner to invoke git rm on all of them is:

git ls-files --stage | awk -v stage=3 -v path=4 '$stage == 2 {print $path}' | xargs git rm

Run it without the final xargs first to check out what files are gonna be deleted.

Try it yourself

Here's a very small sample GitHub repo with that situation. Clone and checkout feature, then try to rebase onto master.

git clone https://github.com/chhh/git-rebase-conflict-resolution
git checkout feature
git rebase -Xtheirs master
Dmitry Avtonomov
  • 8,747
  • 4
  • 32
  • 45
0

If the only conflicts you have are unmerged paths "deleted by them" I think just git add -u will solve the situation.

Moberg
  • 5,253
  • 4
  • 38
  • 54