Duplicate submodules with Git

前端 未结 2 1327
青春惊慌失措
青春惊慌失措 2020-12-08 20:21

I have a project in Git that has several submodules, and I need those submodules to be downloaded and the files available in order to use the main project, and in order for

2条回答
  •  离开以前
    2020-12-08 21:26

    git-new-workdir might not be good solution as discussed here: http://comments.gmane.org/gmane.comp.version-control.git/196019

    It didn't work for me under git 1.7.10.

    I have solved it for my use-case using hard links. I'm running OS X and the filesystem allows creating hard-links to directories: https://github.com/darwin/hlink

    Now I can hard-link submodule directories and git treats them transparently. Hard linking has also nice property that all submodules are fully mirrored including HEAD which is a behavior I prefer in my case.

    Ok, the idea is to have one "master" submodule repo and hard-link all "slave" copies back to it. This will make them all indistinguishable from each other and fully synced.

    CAVEATS:

    1) This works fine as long as relative paths in .git work. In other words you can hard-link only submodules sitting on same directory level in the directory tree. This was my case. I assume you can easily fix it by modifying .gitfiles with your hard-linking task. Note: This should be no issue before git 1.7.10, because previously submodule's .git was a self-contained directory not just plaintext .git file pointing somewhere else.

    2) Hard links may introduce some incompatibilities. For example TimeMachine gets confused because it uses hard links internally for versioning. Make sure you exclude your project directory form TimeMachine.

    Here is an example of my rake task doing the job: https://github.com/binaryage/site/blob/3ef664693cafc972d05c57a64c41e89b1c947bfc/rakefile#L94-115

提交回复
热议问题