- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
感谢@torek 的回答,现在已经解决了
我需要在新添加的内容之上添加更多行,以便 Git 可以向上移动差异 block ,我的意思是:
+a
+b
+c
+
+["foo", "bar", "baz"].map do |i|
+ i
+end
+
["foo", "bar", "baz"].map do |i|
i.upcase
end
Note: I tried with a single line-break instead of
a\nb\nc\n
and it also worked as well
我在 Mac OSX 上使用 Git 2.9
这是一个简化的测试用例:
$ mkdir git-highlight && cd git-highlight
$ touch foo.rb
我添加并提交以下内容:
["foo", "bar", "baz"].map do |i|
i.upcase
end
现在我将文件修改为具有以下内容:
["foo", "bar", "baz"].map do |i|
i
end
["foo", "bar", "baz"].map do |i|
i.upcase
end
如果我运行 git diff
或 git diff --compaction-heuristic
然后我得到以下意外输出:
diff --git a/foo.rb b/foo.rb
index 9056b22..f0d289a 100644
--- a/foo.rb
+++ b/foo.rb
@@ -1,3 +1,7 @@
["foo", "bar", "baz"].map do |i|
+ i
+end
+
+["foo", "bar", "baz"].map do |i|
i.upcase
end
如果您从 GitHub 阅读这篇博文 https://github.com/blog/2188-git-2-9-has-been-released我被引导相信我的输出应该看起来更像:
+["foo", "bar", "baz"].map do |i|
+ i
+end
+
["foo", "bar", "baz"].map do |i|
i.upcase
end
git 的 diffing 算法的想法更智能并且能够识别 block 更改。
我也尝试将以下内容添加到我的 ~/.gitconfig
但它对结果没有任何影响,我仍然得到意外的输出:
[diff]
compactionHeuristic = true
关于我在这里遗漏了什么有什么想法吗?
最佳答案
谈到“git diff 压缩启发式算法不起作用”...Git 2.12(2017 年第一季度)将淘汰该启发式算法。
Git 2.14 will set the indent heuristic instead as the default one .
"
git diff
" and its family had two experimental heuristics to shift the contents of a hunk to make the patch easier to read.
One of them turns out to be better than the other, so leave only the "--indent-heuristic
" option and remove the other one.
参见 commit 3cde4e0 (2016 年 12 月 23 日)Junio C Hamano (gitster
) .
推荐人:Jeff King (peff
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 2ced5f2 ,2017 年 1 月 10 日)
详细信息:
diff
:退出“压缩”启发式When a patch inserts a block of lines, whose last lines are the same as the existing lines that appear before the inserted block, "
git diff
" can choose any place between these existing lines as the boundary between the pre-context and the added lines (adjusting the end of the inserted block as appropriate) to come up with variants of the same patch, and some variants are easier to read than others.We have been trying to improve the choice of this boundary, and Git 2.11 shipped with an experimental "
compaction-heuristic
".
Since then another attempt to improve the logic further resulted in a new "indent-heuristic
" logic.
It is agreed that the latter gives better result overall, and the former outlived its usefulness.Retire "compaction", and keep "indent" as an experimental feature.
The latter hopefully will be turned on by default in a future release, but that should be done as a separate step.
下一个 Git 2.15.x/2.16(2018 年第一季度)的更新:
参见 commit bab7614 (2017 年 10 月 29 日)Carlos Martín Nieto (carlosmn
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 662ac3b ,2017 年 11 月 6 日)
diff
:--indent-heuristic
is no longer experimentalThis heuristic has been the default since 2.14 so we should not confuse our users by saying that it's experimental and off by default.
注意:“git diff --indent-heuristic
”在极端情况下性能不佳,已在 Git 2.19(2018 年第 3 季度)中修复。
参见 commit 301ef85 (2018 年 7 月 27 日)作者 Stefan Beller (stefanbeller
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 791ad49 ,2018 年 8 月 17 日)
xdiff
: reduce indent heuristic overheadSkip searching for better indentation heuristics if we'd slide a hunk more than its size.
This is the easiest fix proposed in the analysis in response to a patch that mercurial took for xdiff to limit searching by a constant.
Using a performance test as:#!python
open('a', 'w').write(" \n" * 1000000)
open('b', 'w').write(" \n" * 1000001)This patch reduces the execution of "
git diff --no-index a b
" from 0.70s to 0.31s. However limiting the sliding to the size of the diff hunk, which was proposed as a solution (that I found easiest to implement for now) is not optimal for cases like:open('a', 'w').write(" \n" * 1000000)
open('b', 'w').write(" \n" * 2000000)as then we'd still slide 1000000 times.
In addition to limiting the sliding to size of the hunk, also limit by a constant. Choose 100 lines as the constant as that fits more than a screen, which really means that the diff sliding is probably not providing a lot of benefit anyway.
关于git - 新的 git diff 压实启发式方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37895083/
场景: Suppose I have a large pseudorandom graph complete with edge weights, but without any coordinate
我有一个巨大的人名列表,我必须在巨大的文本中进行搜索。 只有名称的一部分可以出现在文本中。并且可能存在拼写错误、打字错误或缩写。文本没有标记,因此我不知道文本中人名的开头位置。我不知道这个名字是否会出
我在尝试总结这些启发式算法的最坏情况比率时遇到了一些麻烦(这意味着它满足三角不等式)旅行商问题: 最近的邻居 最近的插入 最便宜的插入 最远插入 最近的邻居: Here它表示 NN 的 w-C 比率为
我正在为 2048 开发一个 AI。到目前为止它非常简单,我基本上是在尝试制作一个由递减方 block 组成的“蛇”,所以完美的游戏应该是这样的: ,虽然这和这个一样好: . 我的启发式方法是使用一个
我从 stdin 中读取了一个正整数 N,然后我试图确定 N 是否是素数。 我知道我可以将 N 除以所有正数直到 sqrt(N),但这很耗时,而且我的算法有时会给出误报,所以我正在寻找一种启发式方法来
我对高估/低估这两个术语感到困惑。我完全了解 A* 算法的工作原理,但我不确定高估或低估启发式算法的效果。 取直接鸟瞰线的平方是否高估?为什么它会使算法不正确?所有节点都使用相同的启发式。 直接鸟瞰线
我有一个问题,由一个有墙、目标和代理的方形迷宫组成。代理只能水平/垂直移动。在每一步,每个智能体从 1 个方格移动。 我必须实现 A* 算法来解决问题,但我很难找到一个很好的启发式算法来解决它。 每次
首先,我看到了这个答案,是的,它解释了 X-Y 启发式算法,但是示例板太简单了,我无法理解一般的启发式算法。 X-Y heuristic function for solving N-puzzle 有
我正在尝试为清晰 map 的吃 bean 人游戏想出一个又好又快的启发式方法。 我的启发式方法是尝试计算吃 bean 人到达 map 上每个有食物的点所需的最小可能距离。我当前的算法基本上是 Prim
我只是玩弄 Python 并发现了一件有趣的事情:我的计算机(i5,3 GHz)在尝试计算 10 ** 10 ** 10 几个小时后就停止运行了。我知道数学不是创建 Python 的目的,但我想知道是
我理解杀手启发式背后的想法以及它为什么有帮助。我正在努力解决的是如何在 Alpha-Beta 搜索例程中实现它。特别是如何保证只先尝试兄弟节点的杀手级 Action ?伪代码会有很大帮助。 最佳答案
我已经实现了 Clarke-Wright 启发法来解决 TSP(基于伪代码 here )。我已附上我在 Matlab 中的实现。然而,它对我来说不够快,并且需要 O(n2) 空间(因为成对距离)。我想
我是一名优秀的程序员,十分优秀!