Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 317
fraxture Avatar asked Aug 20 '16 15:08

fraxture


People also ask

Why git diff does not show changes?

Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.

How does GitHub diff Work?

The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.

How do I view changes side by side in GitHub?

Fortunately, there's a split button in the upper right hand corner that says Unified | Split. Clicking on Split portion of the button will show the before and after changes side by side, which is just my personal preference.


1 Answers

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

like image 69
Jesper Rønn-Jensen Avatar answered Nov 06 '22 16:11

Jesper Rønn-Jensen