Last active
July 9, 2024 20:31
-
-
Save tekin/12500956bd56784728e490d8cef9cb81 to your computer and use it in GitHub Desktop.
An example .gitattributes file that will configure custom hunk header patterns for some common languages and file formats. See https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more for more details.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stick this in your home directory and point your Global Git config at it by running: | |
# | |
# $ git config --global core.attributesfile ~/.gitattributes | |
# | |
# See https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more for more details | |
*.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=objc | |
*.mm diff=objc | |
*.cs diff=csharp | |
*.css diff=css | |
*.html diff=html | |
*.xhtml diff=html | |
*.ex diff=elixir | |
*.exs diff=elixir | |
*.go diff=golang | |
*.php diff=php | |
*.pl diff=perl | |
*.py diff=python | |
*.md diff=markdown | |
*.rb diff=ruby | |
*.rake diff=ruby | |
*.rs diff=rust | |
*.lisp diff=lisp | |
*.el diff=lisp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Additional manually-configured matchers you may want to add to your .gitconfig | |
[diff "rspec"] | |
xfuncname = "^[ \t]*((RSpec|describe|context|it|before|after|around|feature|scenario|background)[ \t].*)$" | |
[diff "swift"] | |
xfuncname = ^[ \t]*((class|func)[ \t].*)$ |
This is great, thanks a lot! Super useful if you're using a less rich editor such as Vim and working mainly out of a terminal.
Thank you so much for this! I work with rspec and capybara a lot and found using the built-in ruby diff for spec files broke the hunk header entirely for them, so I wrote my own regex for specs based on the native ruby regex:
# .gitconfig
[diff "rspec"]
xfuncname = "^[ \t]*((RSpec|describe|context|it|before|after|around|feature|scenario|background)[ \t].*)$"
You can then use "rspec" as a diff driver:
# .gitattributes
*.rb diff=ruby
*_spec.rb diff=rspec
@jimryan that’s super cool, thanks for sharing!
@jimryan Might want to add around
too. Thanks!
@zubin Good point! I've updated the snippet above. Thanks!
Thank you for a great tip.
I found this gist as well and comment here for additional info.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you @citizen428
Edit:
I think you mentioned some other user by accident :)