简体   繁体   中英

Git lfs is updating two .gitattributes. Which one to keep?

I have successfully added a file with git lfs. Now it is updating two.gitattribute files, one with the location.gitattributes and other with the location My_folder/.gitattributes. My_folder is the name of folder where I have my file that is stored to track it with git lfs.

So my question is do we have to push both.gitattribute files in our repo? Both these files have identical changes.

Git uses the attributes the same way it uses .gitignore files: "more local" files add to the rule sets, and rules from any rule set that override previous rules will apply, with the overridden rule not applying. For rules that augment previous rules, both rules apply.

This works recursively, so:

$ cd project
$ git init
... git messages ...
$ mkdir one one/two
$ echo '* text' > .gitattributes
$ echo '* binary' > one/.gitattributes
$ echo '* text' > one/two/.gitattributes

means that all files in all directories are text, except that all files within one/ and all of its sub-directories are binary, except that all files within one/two/ and all of its sub-directories are text.

The LFS wrappers use the .gitattributes file to make Git run "smudge" and "clean" filters on particular files. These filters—supplied by the LFS software, not part of Git—work by removing the entire file contents from Git's view of the file, replacing the file contents with a "pointer file". So the Git repository holds only the pointer files. When you commit such files and push the commits, the LFS wrappers send the "real" file data to a separate, non-Git server.

Anyone extracting just the Git repository will see only the pointer files . To see the real files, a user must install the LFS wrappers and enable the smudge and clean filters. Once the user has done so, checking out such a file triggers the appropriate .gitattributes entry, which runs the pointer file through the "smudge" filter; this filter actives the LFS file-retrieval system, to get the real file from the LFS server, and then secretly replaces Git's attempt to write the pointer file with the real file. So now you'll see the real file.

What that ends up meaning for your question is simple: you need both .gitattributes if and only if there is something in the "inner" .gitattributes that is needed. Otherwise, the "outer" .gitattributes suffices.

So my question is do we have to push both.gitattribute files in our repo? Both these files have identical changes.

You don't push files , in Git: you push commits . Each commit has a full snapshot of every file. You will commit all the necessary .gitattributes files, however many that is, and then git push will send a single commit that contains all those files.

(LFS does, however, push individual files. The .gitattributes file itself is never replaced by the LFS software, since this would break the system: Git has to be able to read the contents of the .gitattributes file, and replacing those contents with a pointer file would mean that Git would not run the LFS filters.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM