Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make --word-diff default in git diff, git gui, gitk

Tags:

git

Is it possible to set an option that git diff is always using --word-diff=color whenever displaying diffs?

I know that there are command line arguments for gitk, git-gui and git diff, but are there config options I can set globally?

I found that this works for git-gui: Adding this to .gitconfig works for guid

[gui]     diffopts = --word-diff --color-words 

But using this, I can not actually pick anything anymore. I get "diff fails to apply" whenever I want to commit any line or chunk.

like image 505
Andreas Mueller Avatar asked Sep 28 '15 20:09

Andreas Mueller


People also ask

What does git diff compare by default?

By default git diff will execute the comparison against HEAD . Omitting HEAD in the example above git diff ./path/to/file has the same effect. When git diff is invoked with the --cached option the diff will compare the staged changes with the local repository.

What is git diff format?

According to the official Git documentation, git diff is used to: “Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, changes resulting from a merge, changes between two blob objects, or changes between two files on disk.”

What is git diff -- name only?

The -z to with git diff --name-only means to output the list of files separated with NUL bytes instead of newlines, just in case your filenames have unusual characters in them. The -0 to xargs says to interpret standard input as a NUL-separated list of parameters.

What is the difference between the git diff and git status?

The main difference between the commands is that git diff is specially aimed at comparisons, and it's very powerful at that: It can compare commits, branches, a single file across revisions or branches, etc. On the other hand, git status is specifically for the status of the working tree.


2 Answers

If you frequently invoke git diff you may define a git alias.

$ git config [--global] alias.df "diff --word-diff=color" 

And then use git df instead of git diff.

like image 59
Alex P. Avatar answered Oct 14 '22 14:10

Alex P.


You can set the options you want to use in git gui with gui.diffopts. For example, for word diff:

git config --global gui.diffopts --word-diff 
like image 42
Jonah Graham Avatar answered Oct 14 '22 13:10

Jonah Graham