how can I add git submodule into git repo as normal directory?

前端 未结 2 1315
暖寄归人
暖寄归人 2021-02-10 12:18

Let\'s see what it is

  • Create two git repo sub & test
mkdir test sub
cd test && git init && touch R         


        
2条回答
  •  萌比男神i
    2021-02-10 13:19

    git add sub
    git commit -m "add sub directory"
    

    I want to treat them as one git repo and push them remotely, but now the files under sub directory can not be included ?

    They are not included because test sees repo sub as nested git repo, and records only its gitlink, or SHA1, and not its url as it would have if sub had been added as a submodule.

    You would need to push sub to a remote url first, and then add it as submodule for test to see sub files.

     cd test
     git submodule add -- /url/to/sub
    

    Or you would need to use a subtree

    cd test
    git subtree --prefix sub /url/to/sub master --squash
    

提交回复
热议问题