When I clone [a] repository [in which the commit that I will choose for git checkout
has a .gitattributes
file in it], does git make sure to read this file and make it effective before checking out files?
Yes.
Is this documented anywhere?
Yes, towards the front of the gitattributes documentation:
When the .gitattributes
file is missing from the work tree, the path in the index is used as a fall-back. During checkout process, .gitattributes
in the index is used and then the file in the working tree is used as a fall-back.
There's a bit of un-clarity here in that the index itself is populated semi-simultaneously with the work-tree population—the whole thing is done as if via one big atomic transaction—but in fact, what this means is that Git creates the index1 from the commit, then uses what's in the index to populate the work-tree.
1This "the" index is actually the new index, stored in index.lock
, that will become the index later via an atomic rename() operation. Before any of that happens, though, Git must scan the entire work-tree and verify that the work-tree update is allowed, then do the work-tree update pseudo-atomically, then rename the index.lock
file to index
to cause the atomic transaction to commit by releasing the lock.