Git合并策略忽略已删除的文件 [英] Git merge strategy to ignore deleted files

查看:990
本文介绍了Git合并策略忽略已删除的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有特殊的分支(发布分支),它是主分支的精确副本,其中一些文件和目录被删除。这个分支没有开发,但它必须与主同步,因此主分区的更新必须不断推送到该分支。



通过执行正常合并( git merge master )我经常碰到类似的问题(例如一个示例README文件):

CONFLICT(删除/修改):README在HEAD中删除并在主文件夹中修改



预期:我尝试合并文件中的更改,我已删除。所以,为了解决它们,我使用 git rm README



要自动化它,我可以使用自动通过指定-X来解决冲突。手册页显示这对我来说是正确的:

这个选项强制相​​互冲突的hunk通过支持我们的版本自动解决。从另一棵与我们不冲突的树的变化反映到
合并结果中。



然而,当我做 git merge -s递归-X我们的主人我仍然得到相同的未解决的删除/修改冲突。我究竟做错了什么?是否有另一种自动化解决冲突的方法?

解决方案

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

  git status | grep'被我们删除'| awk'{print $ 4}'| xargs git rm 

在此之后,您应该像平常一样解决其他冲突,然后提交。



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


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?

解决方案

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.

这篇关于Git合并策略忽略已删除的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆