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

发布于 2024-10-04 03:57:41 字数 133 浏览 1 评论 0原文

我有一个包含大量历史记录的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带上头具痛哭 2024-10-11 03:57:41

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

您将需要 filter-branch 来调整树。该脚本最初需要创建一个存储库,该存储库是存储库中的子模块。每当有更改时,它都需要提交到该内部存储库,并调整父级中的子模块引用,并在该级别提交。

您现在可以发布存储库,没有人能够执行 git 子模块操作,但这就是您想要的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文