我经常用 git add -p somefile
以交互方式仅暂存给定文件中的部分。但是,如果文件有更复杂的更改,则默认差异会出错,交互式补丁命令提供的大块也会出错。git diff
命令有许多选项来改进或自定义差异输出,包括非常有用的 --anchored=<text>
,但是有什么办法可以从 git add -p
获得更好的帅哥吗? ?
最佳答案
您可以尝试以下操作:
git add -p
如前所述 heregit -c diff.algorithm=<algo-name> add -p
git docs 中可用的差异算法,-diff-algorithm={patience|minimal|histogram|myers}
Choose a diff algorithm. The variants are as follows:
default, myers The basic greedy diff algorithm. Currently, this is the default.
minimal Spend extra time to make sure the smallest possible diff is produced.
patience Use "patience diff" algorithm when generating patches.
histogram This algorithm extends the patience algorithm to "support low-occurrence common elements".
diff.indentHeuristic
范围git -c diff.indentHeuristic=true add -p
来自 git docs ,
diff.indentHeuristic
Set this option to true to enable experimental heuristics that shift diff hunk boundaries to make patches easier to read.
但是,基于 this
With Git 2.25 (Q1 2020), you don't even have to specify --indent-heuristic anymore (since it is the default for quite some times now).
, 这个
参数默认设置(为真)。所以可能,尝试将其设置为 false 如果
完全有帮助。
关于git - 如何在 git add 交互式补丁模式中获得更好的帅哥?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59270198/