Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge strategy to ignore deleted files

Tags:

I have special branch (release branch) which is an exact copy of master branch with some files and directories removed. No development is happening on this branch, however it must be in sync with master, so updates on master must be constantly pushed to that branch.

By doing a normal merge (git merge master) I constantly get conflicts like (a sample README file for example):

CONFLICT (delete/modify): README deleted in HEAD and modified in master

which is expected: I try to merge changes in files, that I've deleted. So, to resolve them I jut use git rm README.

To automate it, I though I could use automatic conflict resolution by specifying -X ours. Man pages suggest it is a right thing for me:

This option forces conflicting hunks to be auto-resolved cleanly by favoring our version. Changes from the other tree that do not conflict with our side are reflected to the merge result.

However, when I do git merge -s recursive -X ours master I still get the same unresolved delete/modify conflicts. What am I doing wrong? Is there another way to automate conflict resolution?

like image 428
Vladimir Minakov Avatar asked Jul 04 '12 14:07

Vladimir Minakov


People also ask

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.

How do I merge without deleting?

Copy the cell with the CONCATENATE formula (D2). Paste the copied value in the top-left cell of the range you want to merge (A2). To do this, right click the cell and select Paste Special > Values from the context menu. Select the cells that you want to join (A2 and B2) and click Merge and Center.

How do I make git ignore a folder while merging?

git checkout staging # go to staging branch git checkout dev . # this checkout dev file changes into staging git reset HEAD build # this remove added file in build folder git clean -f # this drops untracked files we just reseted git checkout -- .


1 Answers

There's probably a better way to do this, but I solved a similar problem by doing the merge (with the default merge strategy) and then running

git status | grep 'deleted by us' | awk '{print $4}' | xargs git rm 

After this, you should resolve other conflicts as normal and then commit.

This just deletes all files that had been deleted on the current branch, which I think is what you want.

like image 149
Bryan Head Avatar answered Sep 16 '22 11:09

Bryan Head