Introduce .gitattributes to end the CRLF/LF and binary diff horror, and detect/auto-fix whitespace errors

Created on 30 March 2011, over 13 years ago
Updated 5 August 2023, 11 months ago

In the same vein as #917492: Add a sensible .gitignore file , we should also provide a .gitattributes.

In particular, we could specify the file type for certain extensions (like *.module is a PHP file) so that the hunk headers are more useful. From http://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

diff

The attribute diff affects how git generates diffs for particular files. It can tell git whether to generate a textual patch for the path or to treat the path as a binary file. It can also affect what line is shown on the hunk header @@ -k,l +n,m @@ line, tell git to use an external command to generate the diff, or ask git to convert binary files to a text format before generating the diff.

So the .gitattributes file could be something like

*.engine  diff=php
*.inc     diff=php
*.install diff=php
*.module  diff=php
...

Later additions could deal with attribute substitution on export:

export-subst

If the attribute export-subst is set for a file then git will expand several placeholders when adding this file to an archive. The expansion depends on the availability of a commit ID, i.e., if git-archive(1) has been given a tree instead of a commit or a tag then no replacement will be done. The placeholders are the same as those for the option --pretty=format: of git-log(1), except that they need to be wrapped like this: $Format:PLACEHOLDERS$ in the file. E.g. the string $Format:%H$ will be replaced by the commit hash

Feature request
Status

Fixed

Version

8.0 ⚰️

Component
Base 

Last updated less than a minute ago

Created by

🇺🇸United States bfroehle

Live updates comments and jobs are added and updated live.
  • git

    Used in Documentation issues for documentation related to Git

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024