24

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?

4

4 回答 4

20

可能有更好的方法来做到这一点,但我通过执行合并(使用默认合并策略)然后运行解决了类似的问题

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

在此之后,您应该正常解决其他冲突,然后提交。

这只会删除当前分支上已删除的所有文件,我认为这是您想要的。

于 2013-12-30T20:14:34.027 回答
7
git merge master
git status --porcelain | awk '{if ($1=="DU") print $2}' | xargs git rm
git commit
于 2016-04-07T08:23:23.580 回答
3

通过查看这个问题,看起来我们他们的选项的递归策略不认为删除是冲突。

您可以做的是使用此功能为某些文件指定特定策略。我敢打赌,我们的策略(不是选项)会对这些文件起到作用。

编辑:

如评论中所述,您不能这样做!

如果这对你来说是一个非常重要的特性,你应该明确地联系 Git 邮件列表 ( git@vger.kernel.org )

于 2012-07-04T15:36:24.913 回答
-2

您可以使用 rebase 而不是 merge 来实现发布分支。

于 2012-07-04T17:57:52.110 回答