如何让 git 将 tar 档案透明地视为目录? [英] How to have git treat tar archives transparently as directories?
问题描述
我想要 git 到版本 atar 文件,用于存储库相关功能,例如git-diff(甚至复杂git-merge 冲突解决方案)file 似乎是一个目录,其包含的文件定期提交到 git,除了在结帐时应该再次获得有效的 tar
存档.这是可以实现的吗?
I'd like git to version a tar file such that for repository-related functions such as git-diff (and even sophisticated git-merge conflict solutions) the file appears to be a directory with its included files being committed regularly to git, except that on checkout one should obtain a valid tar
archive again. Is this somehow achievable?
我首先想到使用涂抹/清洁过滤器,但它们只允许您修改存储的文件内容git blob.
I first thought about using smudge/clean filters, but they merely allow you to modify the file contents of the stored git blob.
所以,现在我正在考虑使用 hooks(pre-commit
和 post-checkout
,如此处的建议a>,虽然我也希望有一个 pre-add
过滤器......)它可以简单地在 tar
文件和目录结构之间进行转换,或者为了维护元数据正确,直接与 git 对象(或,作为妥协,使用中间目录但覆盖元数据).但是,在我开始这项可能疯狂的工作之前,是否有
So, now I'm thinking about using hooks (pre-commit
and post-checkout
, as suggested here, though I wish there were a pre-add
filter as well...) which would either simply convert between tar
file and directory structure or, in order to maintain the metadata correctly, directly plumbing with git objects (or, as a compromise, use the intermediate directory but override the metadata). But, before I start with this potentially insane work, is there either
- 实现这一目标的更好方法,或
- 现有的解决方案?
这与 git 能否将 zip 文件视为目录并将 zip 内的文件视为 blob?,尽管我希望由于 tar 文件只是一个串联未经压缩的文件和元数据,处理它们可能更容易.
This is strongly related to Can git treat zip files as directories and files inside the zip as blobs?, although I hope that due to tar files being merely a concatenation of files and metadata without compression, treating them might be easier.
推荐答案
我会建议其中一条评论中提到的内容,即使用 textconv
.
I would suggest what was mentioned in one of the comments, namely to use textconv
.
您可以简单地调用 --textconv
的 git diff
选项,而不是手动使用 cat
.
Instead of manually, using cat
, you could simple invoke the --textconv
option for git diff
.
对于合并,您可以使用 renormalize
选项,或使用 merge.renormalize
将其配置为默认值.
For merging you can use the renormalize
option, or configure this as the default with merge.renormalize
.
我从未真正测试过这个,但我相信它会起作用.
I have never actually tested this, but I believe it will work.
这篇关于如何让 git 将 tar 档案透明地视为目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!