简体   繁体   中英

Git Submodules: Working only on one submodule of a repo

Scenario: In our MainProject, we have more than 12 SubProjects. Some team members works on all SubProjects, Some team members woks on 2-3 SubProjects and Some team members woks only on one SubProject.
Git Repo Strucure: We have created a main repository MainProject.git . And under it we have added different submodules for different projects, say SP1, SP2,...,SP12 .

Problem: Now when any team member clones MainProject, empty directories of all SubProjects are cloned. What we want is, clone only specific submodules which are required for user and don't even want an empty folder.
How is it possible in git ?

clone only specific submodules

This is possible. After cloning, try:

git submodule init
git submodule update <path to specific submodule>

don't even want an empty folder

I don't think this is possible since the submodule folder is a part of superProject repo.

Try git ls-files to verify this. And since we can only clone whole repository, empty folders will get created.


what if someone deleted empty folder

There are two options:

  • You can add all the submodule folders in .gitignore but that is not advisable (See Do you ignore a git submodule in your .gitignore or commit it to your repo? ). The developer working on particular sub module would then have to remove the line before working on it. (Then the developers have to be careful not to push edited .gitignore , hence this doesn't solve the original problem of developers working carelessly)
  • Or, you can use pre-commit git hook to restrict people from deleting folders

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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