Is it possible to make Git aware of an existing .gitmodules file?

前端 未结 2 732
逝去的感伤
逝去的感伤 2021-02-13 05:57

I added a submodule:

git submodule add git://github.com/chneukirchen/rack.git rack

A file .gitmodules was created like:

         


        
2条回答
  •  粉色の甜心
    2021-02-13 06:35

    Ok, so thanks to Adam I found the answer, was kind of obvious but nevertheless, here it is:

    If you check what git submodule add does, you'd notice that it does three things:

    1. Adds the lines to the .gitmodules file,
    2. Clones the repo in the 'path' you determined in the command, and
    3. Adds the module to the .git/config file.

    So, basically the only difference between a repo with a submodule added by hand and the one added via the git submodule command is the contents of the repo itself.

    Answering with the same example, you should:

    $ git clone git://github.com/jgarber/redcloth.git plugins/redcloth
    

    Add the following to the .git/config file*:

    [submodule "redcloth"]
    url = git://github.com/jgarber/redcloth.git
    

    Make sure at least you add them to the git repo:

    $ git add plugins/redcloth
    

    And then check if git actually is "aware":

    $ git submodule status
    0766810ab46f1ed12817c48746e867775609bde8 plugins/redcloth (v4.2.8)
    30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)
    

    *note that the "path" variable you use in the .gitmodules file isn't needed in that file

提交回复
热议问题