git cherry-pick:如何仅考虑由提交修改的行(即不是周围的上下文)? [英] git cherry-pick: how consider only lines modified by the commit (i.e., not the surrounding context)?

查看:143
本文介绍了git cherry-pick:如何仅考虑由提交修改的行(即不是周围的上下文)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有两个分支的项目:

  D --- E分支1 
/
--- A --- C branch2

我想将提交E(但不是D)应用于我使用了 git cherry-pick git mergetool (使用 meld 强大)解决冲突。到现在为止还挺好。然而,假设提交C后文件的状态是

  lineC1 
< context C>
lineC2

以及提交E引入的更改为

  -lineC1 
+ lineE1
<上下文E>
-lineC2
+ lineE2

我希望默认显示的结果是mergetool将是

  lineE1 
< context C>
lineE2

(即,线E1和E2根据提交E而改变,但内部上下文保持不变)。

相反,默认情况下mergetool(即meld)显示:

  lineC1 
<上下文E>
lineC2

这真的没有意义。



如何指示git cherry-pick保留branch2的上下文,并仅考虑对commit E修改的行进行修改?

/ div>

合并通常没有正确的解决方案,程序只能提供启发式的建议。如果建议不是您需要的,您只需编辑它。我认为融合应该向你展示你在屏幕上需要的一切。即使不是,您也可以使用像 git show< sha1>:< file> 这样的命令显示您的文件的每个现有版本以进行复制粘贴。在编辑中间栏后,git会接受它,不管你做了什么改变。



你可能也想试试 git config --global --add merge.conflictstyle diff3



在下一次樱桃挑选(或合并)冲突的结果将被格式化有点不同,并有一些运气更适合您的情况。


I have a project with two branches:

     D---E branch1
    /
---A---C branch2

I want to apply commit E (but not D) on top of branch2.

I used git cherry-pick and git mergetool (with meld) for resolving conflicts. So far, so good.

However, suppose that the state of the file after commit C is

lineC1
<context C>
lineC2

and the change introduced by commit E is

-lineC1
+lineE1
<context E>
-lineC2
+lineE2

I would expect the result shown by default by the mergetool to be

lineE1
<context C>
lineE2

(i.e., lines E1 and E2 changed according to commit E but internal context kept from the current branch).

Instead, the mergetool (i.e., meld) by default shows:

lineC1
<context E>
lineC2

which really makes no sense.

How can I instruct git cherry-pick to keep the context from branch2 and only consider changes to the lines modified by commit E ?

解决方案

There is generally no correct solution for merging, programs can only provide heuristic suggestions. If the suggestion is not what you need, you just need to edit it. I think meld should show you everything you need on the screen. And even if it does not you can use commands like git show <sha1>:<file> to display every existing version of your file for copy pasting. After you have edited the middle column in meld git will accept it as it is, regardless of the changes you made.

You might also want to try git config --global --add merge.conflictstyle diff3

In the next cherry-pick (or merge) the result of the conflict will be formatted a bit differently and with some luck more suitable for your case.

这篇关于git cherry-pick:如何仅考虑由提交修改的行(即不是周围的上下文)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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