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
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?
I have not played with the new features yet, so this may need anywhere from a grain of salt to a full salt lick, but:
Any ideas on what I'm missing here?
The description specifically says that git diff hunks are moved up until reaching a blank line. There is no blank line above line 1; if there were, that might suffice. (It might require even more "above" context—which need not be blank—since the norm is to include three lines of context above and below, and it's not clear from the brief description whether the "moving up" will be stymied by the lack of additional lines.)