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
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
如果您遇到的唯一冲突是“被他们删除”的未合并路径,我认为只需git add -u
就可以解决问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.