Skip to content

Instantly share code, notes, and snippets.

Last active Jun 5, 2022
What would you like to do?
A collection of additional "custom hunk header" patterns for .gitattributes. This provides better context in the diff hunk header.
*.tex diff=tex
*.bib diff=bibtex
*.c diff=cpp
*.h diff=cpp
*.c++ diff=cpp
*.h++ diff=cpp
*.cpp diff=cpp
*.hpp diff=cpp
*.cc diff=cpp
*.hh diff=cpp
*.m diff=matlab
*.py diff=python
*.rb diff=ruby
*.php diff=php
*.pl diff=perl
*.html diff=html
*.xhtml diff=html
*.f diff=fortran
*.lisp diff=lisp
*.el diff=lisp
*.r diff=rstats
*.texi* diff=texinfo
*.org diff=orgmode
*.rs diff=rust
*.pdf diff=pdf
*.png diff=exif
*.jpg diff=exif
*.jpeg diff=exif
*.gif diff=exif
[diff "lisp"]
xfuncname = "^(\\(.*)$"
# xfuncname = "^(\\((cl-)?def(un|macro|method).*)$"
[diff "rstats"]
xfuncname = "^([a-zA-z.]+ <- function.*)$"
[diff "texinfo"]
# from;a=blob;f=.gitattributes;h=c3b2926c78c939d94358cc63d051a70d38cfea5d;hb=HEAD
xfuncname = "^@node[ \t][ \t]*\\([^,][^,]*\\)"
[diff "orgmode"]
xfuncname = "^(\\*+.*)$"
#[diff "css"]
# xfuncname = "^([a-zA-Z#.@][^\\}]*)$"
# xfuncname = "^(.*\\{)$"
[diff "rust"] # Thanks to csabahenk
xfuncname = "^[ \t]*(pub|)[ \t]*((fn|struct|enum|impl|trait|mod)[^;]*)$"
[diff "exif"]
binary = true
# sudo apt-get install libimage-exiftool-perl
textconv = exiftool
[diff "pdf"]
textconv = pdftotext-stdout
# sudo apt-get install pdftotext
# copy the following to a script pdftotext-stdout somehwere in $PATH
# #!/bin/bash
# pdftotext "$@" -
Copy link

ruediger commented May 25, 2013

See gitattributes(5) for more information.

Add the stuff in attributes to your ${XDG_CONFIG_HOME:-~/.config}/git/attributes and the stuff in config to your ${XDG_CONFIG_HOME:-~/.config}/git/config (or ~/.gitconfig)

Copy link

csabahenk commented Jul 4, 2013

Suggested improvement:

[diff "rust"]
      xfuncname = "^[ \t]*(pub|)[ \t]*((fn|struct|enum|impl|trait|mod)[^;]*)$"

Copy link

ruediger commented Sep 4, 2013

Emacs' git-modes comes with several modes for git including gitattributes-mode and gitconfig-mode for editing git attributes and config files.

Copy link

ruediger commented Jan 7, 2014

Copy link

DamienCassou commented Feb 27, 2017

For javascript:

[diff "ecmascript"]
        xfuncname = "^((.*function.*)|([ \t]+it\\(.*))$"

Copy link

baiwfg2 commented Mar 29, 2020

Is there c++ xfuncname ?

Copy link

Konfekt commented Jul 22, 2021

Further set up for diffing binary documents.

Copy link

SuperSandro2000 commented Jun 5, 2022

I am searching for patterns for haskell or nix. Can anyone help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment