在git中,如何增加合并的上下文? [英] In git, how do I increase the context for merges?

查看:59
本文介绍了在git中,如何增加合并的上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我合并较大的更改时,git常常会因无法使用足够的上下文行而变得无可救药地感到困惑.在两个不同的子例程的相似结尾之间,它们混杂在一起,它们都以结尾结尾:

When I merge large changes, git often gets hopelessly confused because it's not using enough context lines. It gets mixed up between the similar-looking endings of two different subroutines that both happen to end with:

.
return 1;
.
}

(此处用于表示空白行的点)

(dots used here to represent blank lines)

当我使用'git diff'时,我可以说-U20来查看20行上下文.但是我可以告诉git在合并时也使用此标志吗?

When I use 'git diff', I can say -U20 to see 20 lines of context. But can I tell git to use this flag when it merges, too?

答案是否可能与合并策略/选项相关,例如:

Could the answer be related to merge strategies/options, such as:

git merge -s recursive -X patience [branch]

就我所知,

推荐答案

在合并过程中,无法增加上下文行. patience diff 算法应该可以更好地处理您的用例.git-merge(1)手册页对此进行了描述:

To the best of my knowledge, there's no way to increase the context lines during a merge. The patience diff algorithm is supposed to handle your use case better. The git-merge(1) man page describes it thus:

使用此选项,合并递归会花费一些额外的时间来避免由于不重要而有时发生的误入歧途匹配的行(例如,来自不同功能的花括号).用这个当要合并的分支出现巨大分歧时.

With this option, merge-recursive spends a little extra time to avoid mismerges that sometimes occur due to unimportant matching lines (e.g., braces from distinct functions). Use this when the branches to be merged have diverged wildly.

由于这看起来与您所描述的情况完全一样,因此耐心似乎是为帮助您而定制的.您可以在这样的一次性分支上进行尝试:

Since this looks exactly like the situation you're describing, patience seems custom-designed to help you out. You can try it out on a throw-away branch like so:

git checkout -b temp_merge_branch master
git merge --strategy-option=patience other_branch

如果合并正常进行,则可以将结果快速转发到master分支.如果没有,您可以丢弃临时分支,然后寻找其他替代方案.

If the merge works cleanly, you can fast-forward your master branch with the results. If not, you can just throw away the temporary branch, and look for other alternatives.

这篇关于在git中,如何增加合并的上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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