How to use submodules publicly, but symlinks to a single clone locally?
I'm having my first Git Submodule experience.
I have some projects that depend on the same subproject. I keep these projects in sync, so I'm using the "submodule branch" feature (eg git submodule add -b master [URL]
).
While I'd like the public GitHub repositories to convey the submodule relationship, in my own workflow I'd really just like to have one clone of the shared codebase on my disk. I thought I could just set up the submodules, and then do a switcheroo with a symbolic link. But when I do, I get this:
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
typechange: draem
So Git apparently sees the fact that it's a symbolic link, instead of following through to the directory.
Is there any workflow where I can appear to be working with submodules, but really only have one clone on my local filesystem?
So Git apparently sees the fact that it's a symbolic link, instead of following through to the directory.
Yes, Git would see such a change, because that submodule is declared in the parent repo as a special entry in the index .
Making a symlink would replace that special entry by a file of another type.
What you could do is try playing with GIT_WORK_TREE
(as in "Including submodules in git checkout to GIT_WORK_TREE
in hook").
But a more simpler solution would be to:
/path/to/sub
). git --work-tree=/path/to/sub
status from within your duplicated submodule folder in your parent repos. You can bind mount the submodule's other directory
sudo mount --bind /path/to/main/repo relative/path/to/submodule
I can't find much info about this method, but saw it listed in this, similar question.
(Appreciate the other advice, but answering with what I've decided to do, because it's easiest.)
Put clones of the submodules you are planning to share in their own directories.
Then set things up how you like in the using projects, each with their own clone of the submodule(s) you are planning to share. Once the projects are set up in a way that new users would get the submodules normally, replace the submodule directories with shared symbolic links to your single local instance where you do your edits, and add them to the .gitignore.
(Rather than just deleting the submodule-based directories, you might want to rename them out of the way. You could then move them back into place and pull them if necessary.)
So the working style is to just never commit the submodule / typechange. As long as you're willing to always track the master branch, people cloning the project will still get the right thing. Meanwhile, you can work with the single repository on your disk.
For projects at a more advanced stage, @VonC probably has the right answer... to not lie to Git, check in the submodules at the appropriate states, and use triggers to manage the updates.
链接地址: http://www.djcxy.com/p/92274.html上一篇: 防止一些提交/代码被合并到主机中