简体   繁体   English

Git lfs 正在更新 two.git 属性。 保留哪一个?

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

I have successfully added a file with git lfs.我已经成功添加了一个带有 git lfs 的文件。 Now it is updating two.gitattribute files, one with the location.gitattributes and other with the location My_folder/.gitattributes.现在它正在更新两个 .gitattribute 文件,一个在 location.gitattributes 中,另一个在 My_folder/.gitattributes 中。 My_folder is the name of folder where I have my file that is stored to track it with git lfs. My_folder 是我的文件所在的文件夹的名称,该文件存储在其中以使用 git lfs 对其进行跟踪。

So my question is do we have to push both.gitattribute files in our repo?所以我的问题是我们是否必须在我们的 repo 中推送 both.gitattribute 文件? 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. Git 使用属性的方式与使用.gitignore文件的方式相同:“更多本地”文件添加到规则集中,任何规则集中覆盖先前规则的规则都将适用,而覆盖的规则不适用。 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.表示所有目录中的所有文件都是文本,除了one/及其所有子目录中的所有文件都是二进制文件,除了one/two/及其所有子目录中的所有文件都是文本。

The LFS wrappers use the .gitattributes file to make Git run "smudge" and "clean" filters on particular files. LFS 包装器使用.gitattributes文件使 Git 在特定文件上运行“涂抹”和“清洁”过滤器。 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".这些过滤器——由 LFS 软件提供,而不是 Git 的一部分——通过从 Git 的文件视图中删除整个文件内容,用“指针文件”替换文件内容来工作。 So the Git repository holds only the pointer files.因此 Git 存储库仅包含指针文件。 When you commit such files and push the commits, the LFS wrappers send the "real" file data to a separate, non-Git server.当您提交此类文件并推送提交时,LFS 包装器将“真实”文件数据发送到一个单独的非 Git 服务器。

Anyone extracting just the Git repository will see only the pointer files .任何仅提取Git 存储库的人都只会看到指针文件 To see the real files, a user must install the LFS wrappers and enable the smudge and clean filters.要查看真实文件,用户必须安装 LFS 包装器启用污迹和清洁过滤器。 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;一旦用户这样做了,签出这样的文件会触发适当的.gitattributes条目,该条目通过“涂抹”过滤器运行指针文件; 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.这个过滤器激活 LFS 文件检索系统,从 LFS 服务器获取真实文件,然后秘密地用真实文件替换 Git 写入指针文件的尝试。 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.最终对您的问题意味着什么很简单:当且仅当“内部” .gitattributes中有某些内容时,您才需要这两个.gitattributes Otherwise, the "outer" .gitattributes suffices.否则,“外部” .gitattributes就足够了。

So my question is do we have to push both.gitattribute files in our repo?所以我的问题是我们是否必须在我们的 repo 中推送 both.gitattribute 文件? Both these files have identical changes.这两个文件都有相同的更改。

You don't push files , in Git: you push commits .您不推送文件,在 Git 中:您推送提交 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.您将提交所有必要的.gitattributes文件,无论有多少,然后git push将发送包含所有这些文件的单个提交。

(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.) (然而,LFS 确实推送单个文件.gitattributes文件本身永远不会被 LFS 软件替换,因为这会破坏系统:Git 必须能够读取.gitattributes文件的内容,并将这些内容替换为指针文件意味着 Git 不会运行 LFS 过滤器。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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