4

Sometimes git diff will return something like this:

diff --git a/file.x b/file.x
index aaaaaaa..bbbbbbb 000000
--- a/file.x
+++ b/file.x

    for (int i = 0; i < 5; i++)
-   {
-       // code
-   }
-
-   // other code
-
-   for (int i = 0; i < 5; i++)
    {
        // more code
    }

Is there any way to force git to show this diff as the following, which more accurately represents the real change?

diff --git a/file.x b/file.x
index aaaaaaa..bbbbbbb 000000
--- a/file.x
+++ b/file.x

-   for (int i = 0; i < 5; i++)
-   {
-       // code
-   }
-
-   // other code
-
    for (int i = 0; i < 5; i++)
    {
        // more code
    }

The difference above is the for (...) line that the diff thinks has been removed is in two different places. I appreciate this is entirely cosmetic, I'd just like to know.

Edit: I have tried

git diff -W a b

as @Michael Durrant suggested, but this does not change the output in this case.

poke
  • 369,085
  • 72
  • 557
  • 602
Ash
  • 3,279
  • 4
  • 28
  • 26
  • 1
    From git's point of view this question makes no sense because git commits entire file versions rather than diffs. The diffs are reconstructed from the commits every time you ask for them. – user1937198 May 31 '15 at 12:31
  • 1
    @user1937198 Yes, so if an option to `git diff` (or `git show`, or whatever) exists that has the desired effect, then that answers the question. This question makes sense to me, even when trying to look at it from git's point of view. –  May 31 '15 at 12:34
  • You could try to use different diff tools, i.e. look for something like http://stackoverflow.com/questions/24162687/git-diff-algorithm-that-does-not-rip-functions-apart-language-aware-diff – kan May 31 '15 at 12:36
  • @hvd, maybe the question should be reworded to make it clear that the change would only apply to the local repo, and not any remotes, because I feel that the way it is asked at the moment it is ambiguous about whether the change should apply to remotes as well. – user1937198 May 31 '15 at 12:38
  • possible duplicate of [Is there something similar to diff --show-c-function in git-diff?](http://stackoverflow.com/questions/16525659/is-there-something-similar-to-diff-show-c-function-in-git-diff) – Michael Durrant May 31 '15 at 12:48
  • @MichaelDurrant That's something else entirely. –  May 31 '15 at 12:52
  • @MichaelDurrant I tried the suggestion in your duplicate answer, but it didn't change the output, so not the desired effect. – Ash May 31 '15 at 20:41

0 Answers0