Update
This is solved now, thanks to @torek's answer
I needed to have more lines above the new addition so that Git could move up the diff'ed block, and by that I mean:
+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
Original Question...
I'm using Git 2.9 on Mac OSX
Here is a reduced test case:
$ mkdir git-highlight && cd git-highlight
$ touch foo.rb
I add and commit the following content:
["foo", "bar", "baz"].map do |i|
i.upcase
end
Now I modify the file to have the following content:
["foo", "bar", "baz"].map do |i|
i
end
["foo", "bar", "baz"].map do |i|
i.upcase
end
If I was to run either git diff
or git diff --compaction-heuristic
then I get the following unexpected output:
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
If you read this blog post from GitHub https://github.com/blog/2188-git-2-9-has-been-released I'm led to believe that my output should look something more like:
+["foo", "bar", "baz"].map do |i|
+ i
+end
+
["foo", "bar", "baz"].map do |i|
i.upcase
end
The idea being git's diffing algorithm is more intelligent and able to identify the block change.
I've also tried adding the following to my ~/.gitconfig
but it doesn't make any difference to the outcome, I still get the unexpected output:
[diff]
compactionHeuristic = true
Any ideas on what I'm missing here?