Search code examples
gitline-endingsgit-configgitattributes

At what point will .gitattribute eol settings be run?


After adding a line to a .gitattributes file in the root of a repository:

*.tt eol=crlf

At what point will what process apply this rule and change the line endings; at merge or at commit or at push? Where will it run them on the client or whatever is storing the origin (bitbucket, stash, github)? Is it different per operating system?

The git man page for .gitattributes is a bit vague under the Checking out and checking in:

These attributes affect how the contents stored in the repository are copied to the working tree files when commands such as git checkout and git merge run. They also affect how Git stores the contents you prepare in the working tree in the repository upon git add and git commit.

When, exactly, are these changes made?

How is this different to a setting in .gitconfig?


Solution

  • End of line conversions are done when

    1. a file is copied from the index to the working directory (this is when CRs would be mapped to CRLFs in your example)
    2. a file is copied from the working directory to the index (this is when CRLFs would be mapped to CRs in your example).

    Since a merge adds files to the index (except in case of conflicts), the rule is indeed run on a merge. Technically, it does not happen on a commit, since a commit just copies files from the index to the repository, but if you pass in the -a option then files are indeed copied to the index, and thus the rule is executed then. A checkout copies files from the index to the working directory, and thus the rule is executed then as well. No rules are executed during a push.