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

2

31

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.

Hesperidium answered 28/9, 2015 at 20:41 Comment(1)
Not a direct answer, but if you install diff-so-fancy it does that for you in a different and I'd say a better way. It doesn't use the Git word diff functionality, but figures out the changed characters itself and highlights them - github.com/so-fancy/diff-so-fancyDasi
T
15

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.

Tom answered 6/1, 2017 at 18:22 Comment(0)
J
3

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
Joellajoelle answered 29/10, 2019 at 18:23 Comment(4)
This does not work, it will break the git gui, at least select the lines to stage does not work, see this discussion: linux - Using diff-highlight with Git GUI - Super UserAmphiarthrosis
There is an issue in the git-gui's github source repo, see here: Visualization of intraline differencesAmphiarthrosis
@Jonah Graham do you realize you're precisely doing the exact same thing that OP already mentioned from their .gitconfig. You're not bringing any new information to this thread. Please read the question you're trying to answer entirely before doing so.Jumbo
@Jumbo please read the question, answer, edits and notice the differences. Welcome to SO!Joellajoelle

© 2022 - 2024 — McMap. All rights reserved.