Possible to enable the word-diff option in github to see more granular changes to a line?
Asked Answered
K

1

29

I'm exploring usage of github for text versioning. A major problem with github is the fact that changes are by line. So if you make a word or phrase change that is rather granular, the whole line appears to have been changed.

In git itself, there's a solution for this because you can activate the --word-diff option on the git diff command. You end up with nice diffs that looks like this:

Is there any support for this in github? Some kind of query param that one can add to a url, similar to the white space exclusions option with ?w=1?

Kingship answered 20/8, 2016 at 15:46 Comment(4)
I have run into the same problem. Please let us know if you have found any solution!Henri
My only discovery was that this works on the Desktop git app.Kingship
feature requested at github.com/isaacs/github/issues/832Hulbert
doesn't blog.github.com/2014-09-04-better-word-highlighting-in-diffs is enough ?Tetrapod
D
8

Github has changed their web pages over time to help users explore more ways of diffing their data.

At the time of your question, you were correct that you could secretly append ?w=1 to ignore whitespace.

Recently they added a control to the Pull-request page, where you can toggle whitespace without using commandline, see screenshot

Screenshot Github pull-request page 2018-08-21

However, (as you ask), it is probably unlikely that Github will add many, many diff settings that helps you differently depending on the context of your problem.

For instance git diff --word-diff may help you in your particular case because of the long lines. But it will give you problems with any +-{} characters, since they are not escaped.

Then you could use git diff --color-words, where you only get the differences in color (and no special characters are inserted.

As a third option you could also use git diff --word-diff-regex="." which will diff any single changed character (as opposed to the standard word breaks above.

I sometimes need to view XML file diffs, and sometimes they are concatenated to a single line. And in that case I can sometimes be lucky and normalize the files before and after. Git also has options for that. See git-attributes for examples involving smudge/clean

So, don't expect too many diff controls on a github page: The controls you may need vary too much to make sense in any usecase. Instead, use the command line

Dysgraphia answered 21/8, 2018 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.