是否可以使用“最小”算法进行交互式添加?

Is it possible to use the “minimal” algorithm for interactive adding?

从快照计算变更集时,

Git 并不总是正确选择大块边界。 git diff 有一个 --diff-algorithm 选项,允许在这方面进行一些调整; git diff --minimal 有时比单独 git diff 给出更好的结果。

有没有办法为 git add -p 获得相同的优化变更集布局(这基本上以交互方式显示 diff 帅哥)?它似乎不允许 --diff-algorithm 选项。

TL;DR 版本

git -c diff.algorithm=minimal add -p

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

详情

在最后一点研究之后将此从评论移至答案:

自 Git 版本 1.8.4 起,交互式添加 perl 脚本(实现 git add -p)遵循 git 配置中的 diff.algorithm 设置。这与 commit 2cc0f53 (12 Jun 2013) by John Keeping (johnkeeping)
(由 Junio C Hamano -- gitster -- in commit 91fc159 合并,2013 年 6 月 27 日) :

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).

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.

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 ...

(在 commit e5c2909 (23 Jun 2013) by Junio C Hamano (gitster) 中进行了修复;修复也在 1.8.4 中)。