Stefan Klein於 2017年6月15日星期四 UTC+8上午12時28分16秒寫道:
>
> Hi,
>
> i do have multiple projects which share the same submodules.
> Each project might point to a different commit of a given submodule, but 
> the submodules are exactly the same.
> No problem with this so far.
> It just bothers me that each submodule occupies disk space, that i have to 
> fetch each submodule multiple times although the local repository for each 
> submodule should be exactly the same.
> Is there an easy way, which doesn't interfere with my colleges, to have 
> the submodule of each project use the same local repository? (and still 
> have their own individual working directory)
> Closest I found so far in documentation are worktrees but i found no clue 
> on how they might work with modules.
>
> regards,
> Stefan
>

rough steps:

0. suppose there are A and B branch in TheSubmodule repo, A is used by 
ProjectA, and B is used by ProjectB
1. move Projects/ProjectA/.git/modules/TheSubmodule to a common folder, say 
Projects/Common/TheSubmodule.
2. delete the key worktree of Projects/Common/TheSubmodule/config file
3. modify Projects/ProjectA/TheSubmodule/.git file, make the gitdir points 
to the new path inner that common folder.
4. rename Projects/ProjectB/TheSubmodule to 
Projects/ProjectB/TheOldSubmodule
5. run command `git worktree add ../../ProjectB/TheSubmodule B` in 
Projects/ProjectA/TheSubmodule
6. delete Projects/ProjectB/TheOldSubmodule and 
Projects/ProjectB/.git/modules/TheSubmodule

Yue Lin Ho

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to