3

我在 Git 下有我的 WordPress 项目,并将 WordPress 作为子模块。我想将我的主题开发保留在一个单独的子模块中,但在当前设置中,并且在将主题设置作为子模块时遇到了一些困难。

这是我的文件系统:

/.git (master repo)
/index.php
/wp-config.php
/wordpress (WordPress repo as a submodule)
/wp-content 
  themes
     test-theme (theme repo)
        .git
        index.php
        (etc...)

现在,当我将我的主存储库推送到 github 并尝试在另一台机器上克隆它时,wordpress 子模块下载正常,但我的主题文件夹没有,并且我收到关于未定义子模块的错误。

我尝试使用它来将我的主题添加为子模块:

git submodule add ./wp-content/themes/test-theme/.git ./wp-content/themes/test-theme

但我收到以下错误:“远程(来源)没有 .git/config 中定义的 url”

我如何将我的主题存储库定义为子模块,当它基本上托管在项目“内部”而不是在线单独的存储库中时?

谢谢。

4

1 回答 1

5

I'm still relatively new to using submodules but I have been trying to do something similar and found two blog posts quite helpful: one by Clint Berry and another by David Winter.

The principle of a submodule is that it should have a separate repo and then when you add that submodule to a new project the add submodule command should be pointing to the repo:

git submodule add https://github.com/youruseraccount/test-theme.git ./wp-content/themes/test-theme
git init
git update

I believe this is why you are getting the error, there is no URL associated with the origin. Look in the files .gitmodule and .git/config to confirm. If I am correct, the git init will add the necessary entries in .git/config and git update this will pull the theme from the repo and put it into the subdirectory.

See here for how to commit changes to the submodule and here for how to remove the submodule.

于 2012-08-06T12:51:35.240 回答