Is there a way to `git submodule add` a repo *without* cloning it?

前端 未结 3 1704
说谎
说谎 2021-02-04 05:49

I have a very long list of repos that I\'m trying to make into one parent repo by making them all submodules.

I\'ve tried adding them to .gitmodules manual

相关标签:
3条回答
  • 2021-02-04 06:28

    Is there a way to trick git into thinking my project has all its (~30K) submodules, without actually needing to clone them all?

    ??? ~30K submodules ?
    Are u trying to clone all github repositories?

    It makes no sense to have so many submodules in a single project.


    Is there a way to trick git into thinking my project has all its

    Nope, this is what submodule is used for, to contain 3rd party (can be yours as well) dependency which will be managed in its own repository.

    As you can see in the image submodule is simply a sub-project inside your project. What you are asking is if there is way to tell git that I have the project while we don't have it at all.

    It cant be done.

    0 讨论(0)
  • 2021-02-04 06:41

    Just use git add.

    The git submodule command is just there to help wrangle nested repositories.

    Some people prefer simple abstractions that dictate and limit what can be done with arbitrarily complicated concrete implementations.

    Git prefers simple implementations that can be made to do unlimited, arbitrary things, relegating abstractions to their proper role as assistants, ways of talking about what's possible. Trying to fit all the things you can do with a dag of snapshots into the blinkered straitjacket of vcs abstractions is crazy-making. A submodule is just a dag reference. "Put the tip of this dag here". The submodule command is just tools to help you hunt down a source for that dag and protect it from all the violent things you do to your poor overworked filesystem every day.

    0 讨论(0)
  • 2021-02-04 06:48

    After a long walk on the internet, I found out that you can achieve what you want by writing directly in the git index and create the “gitlink” file type.

    git update-index [--add] --cacheinfo 160000 <subrepo commit hash> <submod path>
    

    Also do not forget to write the subrepo in .gitmodules (declare the external path, mostly).

    0 讨论(0)
提交回复
热议问题