Sergey Kostrukov
Sergey Kostrukov

Reputation: 1150

Predefined values for .gitattributes

Sometimes people create .gitattributes file with list of known extensions and manually declare them as text or binary:

*.ts text
*.js text
*.json text
*.csv text
*.txt text
*.xml text
# etc.

Does Git have a default (built-in) list of popular file extensions (like .txt, .json etc.)? Does it make sense to manually declare well known extensions in each repo?

What happens if Git doesn't know extension? Does it try to use heuristics by searching EOL symbols, or considers all unknown extensions as binary?

Upvotes: 2

Views: 533

Answers (1)

torek
torek

Reputation: 490078

Does Git have a default (built-in) list of popular file extensions (like .txt, .json etc.)?

No.

Does it make sense to manually declare well known extensions in each repo?

That depends on what you intend to put into your repository, and whether you must deal with Windows.

What happens if Git doesn't know extension?

Git doesn't know extensions at all.

For users with ill-behaved systems (essentially, just Windows, these days), Git defaults to doing a quick scan of each file's content. If the content appears binary, Git guesses that the file is binary and does not do any EOL conversions. If the content appears to be text, Git guesses that it is text and does your selected EOL conversions.

On sane systems (basically everything not-Windows, these days), the default EOL conversion is "do not touch the data", so that even if Git detects the file as text, it does nothing to the data. So here, there's never any need to do anything at all.

Upvotes: 3

Related Questions