Clone of Git repository excluding subdirectory

你说的曾经没有我的故事 提交于 2019-12-10 13:57:34

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4257622/clone-of-git-repository-excluding-subdirectory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!