William Pursell
William Pursell

Reputation: 212248

Is it possible to do "mixed" word-diff in git?

I'd really like to have something like the following:

$ git diff
diff --git a/file b/file
index a7d45cf..4155b93 100644
--- a/file
+++ b/file
@@ -1,2 +1,2 @@
-The quick brown fox jumps over the lazy dog.
-The quick brown fox jumps over the lazy dog.
+The quick brown fox jumped over the lazy dog.
+The quick red fox jumps over the hazy frog.


$ git diff --word-diff
diff --git a/file b/file
index a7d45cf..4155b93 100644
--- a/file
+++ b/file
@@ -1,2 +1,2 @@
The quick brown fox [-jumps-]{+jumped+} over the lazy dog.
The quick [-brown-]{+red+} fox jumps over the [-lazy dog.-]{+hazy frog.+}


$ git diff --word-diff --unimplemented-flag
diff --git a/file b/file
index a7d45cf..4155b93 100644
--- a/file
+++ b/file
@@ -1,2 +1,2 @@
The quick brown fox [-jumps-]{+jumped+} over the lazy dog.
-The quick brown fox jumps over the lazy dog.
+The quick red fox jumps over the hazy frog.

In this case, the basic idea is to be able to set a threshold and if more than N word-diffs appear on a line, the line is presented without the word-diff, but instead as a full line. Does some similar functionality already exist?

Upvotes: 0

Views: 41

Answers (1)

Matthieu Moy
Matthieu Moy

Reputation: 16527

I don't know any such option, but an alternative is diff-highlight, which achieves essentially the same goal: you get a full diff (i.e. without --word-diff), but the words that actually changed from a line to another. In your example, you'd get:

diff-highlight screenshot

Upvotes: 1

Related Questions