简体   繁体   English

如何使用 Git LFS 跟踪存储库的任何子目录中的任何(任意)文件 - 但不跟踪其根目录中的任何文件?

[英]How do I use Git LFS to track any (arbitrary) file in any subdirectory of a repository - but without tracking any files in its root?

I have searched for multiple days to find a solution and did lots of trial and error games without being successful.我已经搜索了多天以找到解决方案,并且做了很多试错游戏,但都没有成功。

The idea is simply to create a library repository for tons of binary (and all related) files which intrinsically makes 100% sure that any added file in the future by any user gets tracked by lfs.这个想法只是为大量二进制(和所有相关)文件创建一个库存储库,这本质上可以 100% 确保任何用户将来添加的任何文件都会被 lfs 跟踪。

However files like.gitattributes, .gitignore, README.md, etc. in the root should of course be excluded.但是,根目录中的 .gitattributes、.gitignore、README.md 等文件当然应该被排除在外。

To understand the wildcard rules of .gitignore one already needs a PhD, the .gitattributes documentation mentions two more exceptions (like forbidding negations) and I can't find anything helpful about whether Git LFS even follows these "nasty rules".要了解.gitignore的通配符规则,已经需要博士学位, .gitattributes文档提到了另外两个例外(例如禁止否定),我找不到任何关于 Git LFS 是否遵循这些“讨厌的规则”的有用信息。

There might be already a few somewhat related questions/answers on so, but I couldn't find anything useful for my problem so far.可能已经有一些相关的问题/答案,但到目前为止我找不到任何对我的问题有用的东西。

Any help is much appreciated.任何帮助深表感谢。 Thanks in advance!提前致谢!

Edit: I've already tested patterns like */* , */*.* , */** , **/* , **/** , /**/* , ... with lfs track "{pattern}" but sometimes (depending on the worktree status) these wildcard patterns get translated into huge unsorted lists of named file fractions in.gitattributes (without shell expansion).编辑: /**/*已经lfs track "{pattern}" */** **/* */*.* */* **/** lfs track "{pattern}"但有时(取决于工作树状态)这些通配符模式会被翻译成巨大的未排序的命名文件分数列表 in.gitattributes (没有 shell 扩展)。 If the wildcards however remain in.gitattributes, then weird things happen like newly matched files not being tracked anymore after merges, or complains about files that should be pointers, files listed in git lfs status suddenly disappear... I should also mention that git lfs migrate import always renders the wildcards in.gitattributes into completely useless lists of existing files.但是,如果通配符保留在.gitattributes 中,则会发生奇怪的事情,例如合并后不再跟踪新匹配的文件,或者抱怨应该是指针的文件, git lfs status中列出的文件突然消失......我还应该提到git lfs migrate import总是将通配符 in.gitattributes 呈现为完全无用的现有文件列表。 And something like git lfs migrate --include="{pattern}" is silently ignored and seems to track just a few arbitrarily selected file extensions?.git lfs migrate --include="{pattern}"这样的东西被默默地忽略,似乎只跟踪一些任意选择的文件扩展名? I even managed to get a repository in a state where I could push to a remote without any errors and afterwards all files were missing on the server - unbelievable.我什至设法在 state 中获得了一个存储库,在那里我可以毫无错误地推送到远程,然后服务器上的所有文件都丢失了 - 难以置信。 To me it seems that Git LFS is totally unreliable and unpredictable.在我看来,Git LFS 似乎完全不可靠且不可预测。 But maybe I'm doing something totally wrong.但也许我做错了什么。

Btw, here is some version info from my tests and Git LFS is installed gloablly:顺便说一句,这是我的测试中的一些版本信息,并且 Git LFS 已安装好:

  • git-lfs/2.3.4 (GitHub; linux amd64; go 1.8.3) git-lfs/2.3.4(GitHub;linux amd64;go 1.8.3)
  • git version 2.26.2 git 版本 2.26.2

I had to do something very similar for a legacy system.我必须为遗留系统做一些非常相似的事情。 Here's what I found worked: ignore everything, then selectively unignore.这是我发现的有效方法:忽略所有内容,然后有选择地取消忽略。 Each parent directory must be individually unignored before its children can be unignored.每个父目录必须单独取消忽略,然后才能取消忽略其子目录。

Let's say you want to store only /bin, /sbin and /usr/local/bin.假设您只想存储 /bin、/sbin 和 /usr/local/bin。

# Ignore everything
*

# Unignore .gitignore so we can commit it.
!.gitignore

# Unignore /bin and its contents
!bin/
!bin/**
!sbin/
!sbin/**

# Unignore /usr/local/bin and its contents
!usr/
!usr/local/
!usr/local/bin/
!usr/local/bin/**

# Reignore log, lock and tmp files.
*.lock
*.log
.#*
*~
.*.swp

The idea is simply to create a library repository for tons of binary (and all related) files which intrinsically makes 100% sure that any added file in the future by any user gets tracked by lfs.这个想法只是为大量二进制(和所有相关)文件创建一个库存储库,这本质上可以 100% 确保任何用户将来添加的任何文件都会被 lfs 跟踪。

Neither Git nor Git LFS are appropriate solutions. Git 和 Git LFS 都不是合适的解决方案。 They are not release managers.他们不是发布经理。 Git LFS adds unnecessary complication, it is not necessary for small binary files like executables. Git LFS 增加了不必要的复杂性,对于像可执行文件这样的小二进制文件没有必要。

I did it as a stopgap solution.我把它作为权宜之计的解决方案。 I was handed a completely uncontrolled legacy system where production files were being edited live;我得到了一个完全不受控制的遗留系统,生产文件正在现场编辑; it was better than nothing, but it sucked.总比没有好,但它很烂。 A better solution should be found ASAP.应该尽快找到更好的解决方案。

In my case, I incrementally replaced its funcionality with managed servers, packaged software, dependency management, individual code repositories, and a proper release pipeline.就我而言,我逐渐用托管服务器、打包软件、依赖管理、单独的代码存储库和适当的发布管道替换了它的功能。 Then I decommissioned the legacy servers.然后我停用了旧版服务器。 I would suggest you also only use this as a stopgap and investigate a proper solution.我建议您也仅将其用作权宜之计并研究适当的解决方案。

An alternative stopgap is to use backup software to make incremental backups.另一种权宜之计是使用备份软件进行增量备份。 The "history" of a binary-only repository is not particularly useful.仅二进制存储库的“历史”并不是特别有用。

暂无
暂无

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

相关问题 如何在不丢失任何提交的情况下将 git 存储库作为另一个 git 存储库的子目录导入? - How to import a git repository as a subdirectory of another git repository without losing any commit? 使用本地 Git LFS repo 来检查是否有任何文件在没有复制的情况下更改。git - Use local Git LFS repo to check if any file changed without copying under .git 是否有任何理由将 GIT-LFS 用于从未更新的大文件 - Is there any reason to use GIT-LFS for large files that are never updated 如何在不提交/添加任何文件或修改任何文件的情况下检查远程 GIT 存储库权限 - How to check remote GIT repository permission without commit/add any files or modify any files 如何克隆包含Git LFS文件的存储库? - How do I clone a repository that includes Git LFS files? Git:如何从索引中删除文件而不删除任何存储库中的文件 - Git: How to remove file from index without deleting files from any repository 如何从git add index中删除文件而不从任何存储库本地删除文件 - How to remove file from git add index without locally deleting files from any repository 如何阻止Git跟踪来自此提交的文件的任何更改? - How do I stop Git from tracking any changes to a file from this commit forward? 将GIT存储库文件导入TFS,无需任何GIT行李 - Import GIT Repository files into TFS without any GIT baggage git只跟踪一个没有任何文件的目录 - git only tracking a single directory without any files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM