1

Adding annotated functions to an existing source file produces mis-aligned diffs. For example, consider adding the provideNewThing method:

@Provides
Foo provideFoo() {...}

@Provides
NewThing provideNewThing() {...} 

@Provides
Bar provideBar() {...}

Running git diff on the command line will show:

     @Provides
     Foo provideFoo() {...}

     @Provides
+    NewThing provideNewThing() {...}
+
+    @Provides
     Bar provideBar() {...}

This is not ideal. It appears I've introduced the @Provides annotation to provideBar. A closer look shows otherwise, but it's easy to miss.

Ideally there is a git diff <some-options> which outputs:

     @Provides
     Foo provideFoo() {...}
+
+    @Provides
+    NewThing provideNewThing() {...}

     @Provides
     Bar provideBar() {...}

Is this possible?

2
  • Have you tried git diff --diff-algorithm=patience ? Commented Mar 21, 2017 at 17:13
  • Yes, the diff algorithms offered by git behave the same for this example. Commented Mar 21, 2017 at 20:20

1 Answer 1

1

Yes, sometimes diff alignment can be difficult to identify. In this case it is simple, but I have encountered scenarios I need to keep track of what was added where. I use kdiff3 - Manual diff alignment.

To add manual diff alignment in KDiff3:

  • Select text in one child window
  • Hit Ctrl+Y
  • Select text in another child window
  • Hit Ctrl+Y

Illustration

Notice the diff alignment in the screenshot attached.

Sign up to request clarification or add additional context in comments.

1 Comment

I've toyed with the idea of configuring a windowed diff tool for quick reviews; it never seems worthwhile. For big reviews, this manual diff alignment feature rocks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.