Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - how to automatically resolve "deleted by us" conflict when cherry-picking

I run the following command:

git cherry-pick SHA --strategy-option theirs

and get a conflict like this waiting for manual resolution:

deleted by us: SOME_FILE

Is there a way to make git automatically resolve such conflicts by adding files deleted by us?

like image 352
Legat Avatar asked Apr 10 '17 20:04

Legat


People also ask

How do you resolve deleted by US conflict?

'deleted by us' means the file is deleted in the commit which you are trying to do a cherry-pick. It is not file is deleted by you. Git tells that the file was deleted in some other commit, and allows you to decide to retain it (git add) or to remove it. You can do git cherry-pick --continue once you sort this out.

Can git resolve conflicts automatically?

When you pull or merge branches, Git will select the recursive strategy as default. The recursive strategy only can detect and do merges which involve renames, but cannot use detected copies. The ours option forces conflicted parts to be automatically resolved by favoring 'our' version.

How do I fix a merge conflict with deleted files?

Select Stage Changed Files To Commit (Ctrl-I) from Commit menu. Enter a commit comment like "deleted conflicting file" Commit (ctrl-enter) Now if you restart the merge it will (hopefully) work.


2 Answers

deleted by us are the new files which you added in your commit (getting cherry picked). But these files are not present in the current branch (the one in which you are cherry-picking into).

So in this case you have to add these files manually by running:

git add <file-path>

However if you think, these files will no longer be needed in the current branch after cherry picking, in that case you can do:

git rm <file-path>
like image 98
Rahul R. Avatar answered Sep 20 '22 18:09

Rahul R.


If you are sure you want to add all "deleted by us" files, you could do:

git status | sed -n 's/deleted by us://p' | xargs git add

or, if you want to remove all "deleted by us" files:

git status | sed -n 's/deleted by us://p' | xargs git rm
like image 24
Simon Edlund Avatar answered Sep 20 '22 18:09

Simon Edlund