是否可以使用“最小"算法进行交互式添加? [英] Is it possible to use the “minimal” algorithm for interactive adding?

查看:66
本文介绍了是否可以使用“最小"算法进行交互式添加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从快照计算变更集时,Git并不总是正确选择大块边界. git diff 有一个-diff-algorithm 选项,可以对此进行一些调整; git diff --minimal 有时会比单独使用 git diff 产生更好的结果.

Git doesn't always choose hunk boundaries correctly, when calculating a changeset from snapshots. git diff has a --diff-algorithm option that allows some tweaking in this regard; git diff --minimal sometimes gives better results than git diff alone.

是否有一种方法也可以为 git add -p (它基本上以交互方式显示 diff 块)获得相同的优化变更集布局?似乎不允许使用-diff-algorithm 选项.

Is there a way to get the same optimised changeset layout also for git add -p (which basically shows the diff hunks interactively)? It doesn't seem to allow the --diff-algorithm option.

推荐答案

TL; DR版本

git -c diff.algorithm=minimal add -p

(需要Git 1.8.4或更高版本).

(requires Git version 1.8.4 or newer).

在最后研究之后,将其从评论中移至答案:

Moving this from comment to answer after the last bit of research:

从Git 1.8.4版开始,交互式add perl脚本(实现了 git add -p )遵循git配置中的 diff.algorithm 设置.这与 commit 2cc0f53 (2013年6月12日)结合在一起://github.com/johnkeeping"rel =" nofollow> John Keeping( johnkeeping ).
(由 Junio C Hamano合并- gitster -提交91fc159 ,2013年6月27日):

Since Git version 1.8.4, the interactive add perl script (which implements git add -p) obeys the diff.algorithm setting in your git configuration. This went in with commit 2cc0f53 (12 Jun 2013) by John Keeping (johnkeeping).
(Merged by Junio C Hamano -- gitster -- in commit 91fc159, 27 Jun 2013) :

以交互方式进行大块交易时,有时使用替代diff算法,将更改分成更大的块逻辑方式.这是不可能的,因为管道命令由add--interactive调用时忽略"diff.algorithm"配置选项(应有的选择).

When staging hunks interactively it is sometimes useful to use an alternative diff algorithm which splits the changes into hunks in a more logical manner. This is not possible because the plumbing commands called by add--interactive ignore the "diff.algorithm" configuration option (as they should).

由于add--interactive是一个瓷器命令,因此应该遵守这一点配置变量.为此,请使其读取diff.algorithm和将其值传递给底层的diff-index和diff-files调用.

Since add--interactive is a porcelain command it should respect this configuration variable. To do this, make it read diff.algorithm and pass its value to the underlying diff-index and diff-files invocations.

此时,请勿在"git add","git reset"或"git"中添加选项结帐"(所有这些都可以调用git-add--interactive).如果用户想要覆盖他们可以使用的命令行上的值:

At this point, do not add options to "git add", "git reset" or "git checkout" (all of which can call git-add--interactive). If a user wants to override the value on the command line they can use:

   git -c diff.algorithm=$ALGO ...

(已在提交e5c2909 中修复)(2013年6月23日)由 Junio C Hamano( gitster );此修复程序也位于1.8.4中).

(with a fix in commit e5c2909 (23 Jun 2013) by Junio C Hamano (gitster); the fix is also in 1.8.4).

这篇关于是否可以使用“最小"算法进行交互式添加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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