Git 子模块:您可以进行本地未提交的编辑吗?

发布于 2024-11-25 12:13:52 字数 232 浏览 2 评论 0原文

我的项目中有一个 git 子模块,它由一组配置文件组成,然后需要在每个项目的基础上进行一些调整。

是否可以使用子模块来做到这一点,或者我在这里做事的方式是错误的?显然我不想将更改提交回子模块的存储库,因为它们是特定于项目的。

任何提示或指示将不胜感激。

编辑:请注意,这些本地编辑是项目本地的,项目在部署到服务器(使用 git 和 Fabric)时需要保留这些更改。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清醇 2024-12-02 12:13:52

局部改变是可以的,但实际上不太可行。

Git 会注意到子模块发生了更改,并将向您显示。您无法在超级模块中提交更改子模块,因为这些更改不会推送到某个地方。因此,当有人尝试签出该子模块时,git 会抱怨,因为它找不到为该子模块记录的提交。

如果这是每个项目而不是每台计算机的差异,您可以在子模块存储库中创建一个分支,在其中进行项目特定的更改。然后可以将这些更改提交到子模块并推送。

您必须自己决定是否希望这些更改成为子模块存储库的一部分,但这是使用 git 实现此目的的唯一方法。

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.

许久 2024-12-02 12:13:52

我使用的一种方法是在子模块目录中使用指向项目源文件的符号链接。例如,在 Drupal 网站中:

/project
    /drupal
    /sites

如果您不熟悉 Drupal,则 sites 目录将包含任何其他模块、主题或多站点信息,并且通常位于 Drupal 根内部(在此案例,/project/drupal)。在您的项目中,drupal 将替换为您的主代码库,sites 将包含您的项目特定设置。

在本例中,drupalproject 的子模块,指向官方存储库。我添加了从 /project/drupal/sites/project/sites 的符号链接,因此对 sites 的修改会在项目级别签入,但 Drupal 仍然可以假装它是一个子目录。

希望类似的设置适用于您的项目。值得注意的一件事是,符号链接将使 sites 中的更改也出现在 drupal 中,因此您可能需要将符号链接添加到 .gitignore< /代码> 文件。另一个缺点是,您必须为设置项目的每台计算机重新配置符号链接,但这很容易成为部署脚本的一部分。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文