Reputation: 797
Discussing the propagation of changes to .gitattribute to other repos got me thinking. What if I'm cloning an existing repository that has a .gitattribute?
This file might specify to git which files are to be considered text and which are not. When I clone this repository, does git make sure to read this file and make it effective before checking out files?
I did some experimentation and it seems to work, as I would expect.
Is this documented anywhere?
PS: Whether the .gitattributes file affects itself is not in scope of this question.
Upvotes: 2
Views: 2022
Reputation: 490078
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.
Upvotes: 3
Reputation: 27908
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.
https://git-scm.com/docs/gitattributes#_effects
Upvotes: 1