简体   繁体   English

与另一个仓库共享git下的文件子集,维护提交

[英]share subset of files under git with another repo, maintaining commits

I have a GitHub repo used to track changes in a set of small scripts (all functionally independent). 我有一个GitHub存储库,用于跟踪一组小脚本(所有功能独立)中的更改。

I also am part of a lab GitHub repo used to collect useful scripts written by various people in our group. 我也是GitHub回购实验室的一部分,该仓库用于收集由我们小组中的不同人员编写的有用脚本。

I want to push changes made to my scripts to the shared repo, but I don't want to have them be exclusively tracked under that repo, nor do I want modifications made there to overwrite my master copies. 我想将对脚本所做的更改推送到共享存储库中,但是我不想让它们仅在该存储库下进行跟踪,也不希望在此处进行修改以覆盖我的主副本。

The approach I've taken is to run a command to copy the scripts into the shared repo every time I change something, but this means I have to make a separate commit in that repo, too. 我采用的方法是每次更改内容时都运行命令将脚本复制到共享存储库中,但这意味着我也必须在该存储库中进行单独的提交。 Every time I Google this I end up at an answer mentioning submodules , but I feel like that's overengineered for what I want to do. 每次使用Google时,我都会得到一个提及submodules的答案,但是我觉得这对于我想做的事情来说是过度设计的。

Is there any way to integrate commits from my primary repo into the secondary repo for only these files? 有什么方法可以将主要存储库中的提交仅集成到这些文件的辅助存储库中?

The problem you'll run into is the phrase "commits...for only those files". 您会遇到的问题是短语“仅对那些文件提交...”。 The complete content tree is an integral part of a git commit. 完整的内容树是git commit的组成部分。 For example, if you use git filter-branch with the subdirectory-filter , it appears to modify every commit to remap a specific directory as the worktree root; 例如,如果您将git filter-branchsubdirectory-filter ,它似乎会修改每次提交,以将特定目录重新映射为工作树根。 but it doesn't really do that because it can't. 但实际上并不能这样做,因为不能。 What it does is create new commits, with a history parallel to the old commits, with the modified work tree directory structure. 它的作用是创建新的提交,其历史记录与旧的提交平行,并具有修改后的工作树目录结构。

If you can structure the shared repository so that each contributor's scripts get their own directory, then submodules would indeed be an option. 如果您可以构建共享存储库的结构,以便每个贡献者的脚本都拥有自己的目录,那么子模块确实是一个选择。 I understand you feel it's over-engineered, but that's based on your thinking that moving "part of a commit" is an easy idea, which is leading you to underestimate how much complexity you should encounter. 我了解您认为它是过度设计的,但这是基于您的想法,即移动“一部分提交”是一个简单的想法,这使您低估了应该遇到的复杂程度。

Otherwise, I think finding a way to automate the copy-based approach is the best you'll get. 否则,我认为找到一种使基于副本的方法自动化的方法是最好的。

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

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