不包含子目录的Git存储库的克隆 [英] Clone of Git repository excluding subdirectory

查看:130
本文介绍了不包含子目录的Git存储库的克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有很多历史的Git仓库。我想让其他人可以访问它,但其中的一个目录包含无法分发的专有代码。有没有什么办法可以使存储库的克隆(包含历史记录)排除该目录?



额外奖励:我还希望能够将更改合并到在旧的主存储库中创建的'公共'代码复制到克隆中。

解决方案

你不能这样做,除非你愿意重写每个提交哈希。如果您决定重写存储库的历史记录以排除该目录,则必须与任何作为存储库贡献者或使用者的人协调。



您需要到过滤分支来调整树。该脚本需要最初创建一个存储库,该存储库是存储库中的子模块。在任何时候发生变化时,它都需要提交到内部存储库,并调整父级中的子模块引用,并在该级别进行提交。



现在可以发布回购和没有人能够做一个git子模块操作,但这就是你想要的。


I have a Git repository with a lot of history. 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. 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.

这篇关于不包含子目录的Git存储库的克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆