Clone of Git repository excluding subdirectory
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 contain开发者_运维技巧s 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.
精彩评论