use git's word-diff for latex files

I would like to have git diff outputs me regular diffs for all files, except *.tex. For *.tex files, I would like to see the output of git diff --word-diff.

I was playing around with .gitattributes and .gitconfig, but the furthest I got was to get a partial display for one .tex file, followed by a crash.

  • Cloning a git repository creates a subdirectory where it is cloned to - why?
  • Docker Hub - Automatic build on tag with regex match not triggered
  • Closing, then reopening a pull request with some new commits
  • How to reduce disk space usage in a large repository?
  • Moving from CVS to git: $Id:$ equivalent?
  • git apply -v, does it return anything when it has been patched successfully?
  • Is it possible to get this behaviour?

    My .gitattributes:

    *.tex diff=latex
    

    .gitconfig:

    [diff "latex"]
        wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"
        command = ~/bin/word-diff.sh
    

    and word-diff.sh:

    #!/bin/sh 
    git --no-pager diff --color-words "$2" "$5"
    

  • How to get the snapshot of code with an commit number but forget the branch after merges?
  • Git magic references
  • Git: squashing material shared between branches
  • How to get change logs from two repositories configured in Jenkins
  • How to find and restore one single file from git?
  • On conflict, GitHub for Windows puts me in “rebasing” state, how to go from there?
  • One Solution collect form web for “use git's word-diff for latex files”

    Can you post (or link to) a complete example? I’ve set up exactly what you’ve described and it seems to work fine. That is, the diff output highlights words rather than lines, and all of the changes I made were included (that is, it didn’t crap out early or anything). The only anomaly was that diff would always exit with:

    external diff died, stopping at foo.tex.
    

    This happens because git diff, when run in the manner in which you’re using it, behaves like the standalone diff tool: it exits with a nonzero exit code if the files differ. Git doesn’t expect this behavior; it assumes that your custom command will always execute successfully and that error exit codes indicate an actual problem.

    Git already knows that the files are difference and does not require the external command to make this determination. The external command is strictly a formatting tool.

    If you modify your diff-words.sh script to always exit successfully, things should work out better:

    #!/bin/sh
    git --no-pager diff --color-words "$2" "$5"
    exit 0
    
    Git Baby is a git and github fan, let's start git clone.