简体   繁体   English

克隆的Git存储库不包括子目录

[英]Clone of Git repository excluding subdirectory

I have a Git repository with a lot of history. 我有一个有很多历史的Git存储库。 I'd like to make this accessible to others, but one of the directories in it contains proprietary code that can't be distributed. 我想让其他人可以访问它,但其中一个目录包含无法分发的专有代码。 Is there any way I can make a clone of the repository (with history) that excludes that directory? 有没有什么办法可以克隆那个排除该目录的存储库(有历史记录)?

Bonus: I'd also like to be able to merge changes to the 'public' code made in the old, main repository into the clone. 额外奖励:我还希望能够将对旧主存储库中的“公共”代码的更改合并到克隆中。

You cannot do that unless you are willing to rewrite each commit hash. 除非您愿意重写每个提交哈希,否则不能这样做。 If you decide to rewrite the history of the repository to exclude that directory, you will have to coordinate with anyone that is a contributor or consumer of the repository. 如果您决定重写存储库的历史记录以排除该目录,则必须与作为存储库的贡献者或使用者的任何人进行协调。

You will need to filter-branch to adjust the tree. 您将需要filter-branch来调整树。 The script will need to initially make a repository that is a submodule within the repository. 该脚本最初需要创建一个存储库,该存储库是存储库中的子模块。 It will need to commit to that inner repository anytime there is a change and adjust the submodule reference in the parent, committing that at that level as well. 它需要在任何时候进行更改时提交到内部存储库并调整父模块中的子模块引用,并在该级别提交该模块。

You can now publish the repo and no one will be able to do a git submodule operation but that's what you want. 您现在可以发布repo,没有人能够执行git子模块操作,但这就是您想要的。

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

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