search

Home  >  Q&A  >  body text

How to clone a git repository with submodule with the minimum code? Compare git clone --depth=1

When simply downloading and using the software from github, you can use the depth parameter to download the first code. However, for projects with submodules, execute git submodule update --init --recursive --depth=1 because the submodule is a shallow clone. , so the target commit cannot be checked out.

Is there any solution to this situation?

怪我咯怪我咯2768 days ago1150

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-02 09:53:54

    I only found a method that fetch/clone once, which is quite troublesome:

    1. git submodule update --init --depth=1 At this time, the commit obtained by clone is usually not the one registered by the submodule, so an error will be reported

    2. git ls-tree HEAD:(submodule的路径) Find the commit you want, such as

      `160000 commit abb03163aeafb8b7fc1efd2413d9f077bcdbeed9  tidy-html5` 的 `abb031`就是
    3. cd to the clone repo of submodule (such as .git/modules/tidy-html5), fetch那个commit git fetch abb031

    4. git submodule update --no-fetch

    reply
    0
  • Cancelreply