Git submodules: can you make local, un-committed edits?
I've got a git submodule in my project that consists of a set of configuration files, which 开发者_运维百科then need a tiny bit of tweaking on a per-project basis.
Is it possible to do this with submodules, or am I doing things the wrong way here? Obviously I don't want to commit back the changes to the submodule's repository, as they're project-specific.
Any tips or pointers would be much appreciated.
EDIT: Note that these local edits are local to the project, and the project needs to retain these changes when it gets deployed to the server (using git and fabric).
It is possible to make local changes, but it's not really feasible.
Git will notice that the submodule has changes, and will show that to you. You cannot commit the changes submodule in the supermodule, because those changes are not pushed somewhere. So when someone tries to checkout that submodule, git will complain, because it can't find the commit that has recorded for that submodule.
If it's a per project and not a per-machine difference, you can create a branch in the submodule repository where the project specific changes are made. These changes then can be commited to the submodule and be pushed.
You have to decide for yourself if you want these changes be a part of the submodule repository, but this is the only way you can do it with git.
One approach I've used is having symlinks in the submodule directory that point to the project's source files. For example, in a Drupal website:
/project
/drupal
/sites
If you're not familiar with Drupal, the sites
directory would contain any additional modules, themes, or multisite information, and is typically located inside the Drupal root (in this case, /project/drupal
). In your project, drupal
would be replaced by your main codebase, and sites
would contain your project-specific settings.
In this case, drupal
is a submodule of project
that points to the official repository. I added a symlink from /project/drupal/sites
to /project/sites
, so modifications to sites
are checked in at the project level, but Drupal can still pretend it's a subdirectory.
Hopefully a similar setup could work for your project. One thing worth noting is that the symlink will make changes in sites
appear in drupal
as well, so you would probably want to add the symlink to your .gitignore
file. The other downside is that you'd have to reconfigure the symlink for each machine you set up the project on, but that could easily be part of your deployment script.
精彩评论