Is it possible to do a partial merge with --ff-only changes?

二次信任 提交于 2019-12-22 12:55:09

问题


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.

Edit: 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. Identify all changes with the information of who made the change (with something like git diff): file1 (both sides) file2, file5 (my side) and file3 and file6 on their side.
  2. Merge only specific one-sided changes (from their side): After I merge my local with the remote, I should have file3 and file6 as modified in their remote branch and file1,file2,file5 as modified in my local branch. I will deal with file1 and file5 vs file6 manually.

回答1:


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

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

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.

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.




回答2:


You could declare a merge driver similar to "Git - how to force merge conflict and manual merge on selected file".

That driver would use git merge-file, except you can test its exit value:

The exit value of this program is negative on error, and the number of conflicts otherwise.

If the merge was clean, the exit value is 0.

So if it returns 0, you can let the merge continue (your merge driver exits with status '0')

In any other cases, you will force a manual merge by exiting with a status '1'.



来源:https://stackoverflow.com/questions/24348953/is-it-possible-to-do-a-partial-merge-with-ff-only-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!