解决已添加和已删除的冲突Git

时间:2016-10-20 14:23:50

标签: git git-merge merge-conflict-resolution git-merge-conflict

我有一个分支release-x.x.x,我想合并到主人。但是,当我执行拉取请求时,它有数百个合并冲突。我认为这是由于我执行的Swift 3迁移。无论哪种方式,我都希望在合并到release-x.x.x时使用master中的所有文件版本。我完成了checkout release-x.x.xgit merge -s recursive -X ours master。我正在反向执行此操作,以便我可以解决release-x.x.x上的冲突,然后在master上创建一个拉取请求并保留所有提交历史记录。

当我运行git status时,这是一些输出:

added by us:     Pods/FirebaseCrash/Frameworks/frameworks/FirebaseCrash.framework/FirebaseCrash
added by us:     Pods/FirebaseCrash/Frameworks/frameworks/FirebaseCrash.framework/Headers/FIRCrashLog.h
added by us:     Pods/FirebaseCrash/Frameworks/frameworks/FirebaseCrash.framework/Headers/FirebaseCrash.h
added by us:     Pods/FirebaseCrash/Frameworks/frameworks/FirebaseCrash.framework/Modules/module.modulemap
deleted by them: Pods/FirebaseCrash/README.md
deleted by them: Pods/FirebaseCrash/batch-upload
deleted by them: Pods/FirebaseCrash/upload-sym
deleted by them: Pods/FirebaseCrash/upload-sym-util.bash
deleted by us:   Pods/FirebaseInstanceID/CHANGELOG.md
added by us:     Pods/Intercom/Intercom/Intercom.framework/Versions/A/Intercom
both added:      MyProject/Base.lproj/Localizable.stringsdict
both deleted:    MyProject/Localizable.stringsdict
both added:      MyProject/en-HK.lproj/Localizable.stringsdict

我认为我想保留added by usboth added并保留任何标记为deleted by them的内容,因此我已暂存这些文件。我如何处理deleted by usboth deleted?如果我尝试git rm Pods/FirebaseInstanceID/CHANGELOG.md,我会收到错误:Pods/FirebaseInstanceID/CHANGELOG.md: needs merge。我在这里走的是正确的轨道吗?

1 个答案:

答案 0 :(得分:3)

是的,你正走在正确的轨道上。要按照您指定的方式解决合并问题,您应该git rm标记为deleted by usboth deleted的所有文件。

needs merge错误应该只是一个警告。当我在合并中由一侧删除的文件上运行git rm <file>时,我得到:

<file>: needs merge
rm '<file>'

后续git status表示该文件已被删除(并且删除已暂存)。