是否可以使用--ff-only更改进行部分合并? [英] Is it possible to do a partial merge with --ff-only changes?

查看:94
本文介绍了是否可以使用--ff-only更改进行部分合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地分支,需要与远程合并.远程分支机构和本地分支机构都有许多不同的提交(在各种文件上).是否可以识别和合并仅具有快进类型(远程)更改的文件?我想手动处理所有其他更改.双向合并时,git merge --ff-only不会合并任何内容.

I have a local branch that needs to be merged with the remote. Both remote and local branches have lots of different commits (on various files). Is it possible to identify and merge the files which have only fast-forward type (remote-side) changes? I would like to deal with all the other changes manually. git merge --ff-only does not merge anything when there is any two-sided changes.

我想更清楚地说明问题.假设原始文件(在父节点上)是file1,file2,file3,file4.在我的本地分支中,我修改了文件1,文件2,删除了文件4,添加了文件5.在远程分支中,他们修改了文件1,文件3,删除了文件4,添加了文件6.我想执行以下操作:

I would like to make the question more clear. Let's say the original files (on parent node) are file1, file2, file3, file4. My local branch, I modified file1, file2, deleted file4, added file5. In their remote branch, they modified file1,file3, deleted file4, added file6. I would like to do the following:

  1. 使用谁进行更改的信息(使用git diff之类的信息)来标识所有更改:file1(两面)file2,file5(我这边)以及file3和file6在他们这边.
  2. 仅合并特定的单方面更改(从他们的角度来看):将本地与远程合并后,我应该在远程分支中修改了file3和file6,在本地分支中修改了file1,file2,file5.我将手动处理file1和file5与file6.

推荐答案

git read-tree 是低级别的合并准备,没有实际的冲突解决方案.一种简单的方法是

git read-tree is the low-level merge prep, everything short of actual conflict resolution. One easy way is

git merge -s ours --no-commit other # no-op merge, just sets up parents
git read-tree -um $( git merge-base HEAD other ) HEAD other
# manual resolution here
git commit

git merge-s ours --no-commitother# no-op merge, just sets up parents
git read-tree -um $(git merge-baseHEADother) HEADother
#manual resolution here
git commit

会在两个分支中为所有内容保留不同的新内容以进行手动解析,但会接受所有至多一个新版本的文件.您可能希望read-tree--aggressive选项可以将整个文件的删除和添加作为普通更改进行处理.

which leaves everything with different new content in both branches for manual resolution but accepts all at-most-one-new-version files. You might want read-tree's --aggressive option, to handle whole-file deletion and addition as an ordinary change.

出于安全考虑,请检查 git merge-base --all HEAD other .如果这显示多个基准(每个分支上的最新合并具有共同的父级时将如此),则git的(默认)递归"合并策略将派生基准内容,从而产生比实际基准更好的自动解析结果,并且您可能希望您的手动分辨率格外小心.

As a safety play for an unlikely case, check the output of git merge-base--all HEADother. If that shows multiple bases (as it will when the most recent merges on each branch have common parents), git's (default) "recursive" merge strategy would have derived base content that produces better automatic resolution results than the actual bases, and you might want to take extra care with your manual resolution.

这篇关于是否可以使用--ff-only更改进行部分合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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