Opposite/reverse of “git submodule absorbgitdirs”?

前端 未结 2 1817
梦毁少年i
梦毁少年i 2020-12-16 17:45

How can I do the reverse of git submodule absorbgitdirs? I.e. move a submodule\'s .git information out of superproject/.git/modules/

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 18:18

    Note that this would make superproject/path/to// a nested Git repo, whose SHA1 would still be recorded by the parent project.

    To keep the exact same state, you can copy superproject/.git/modules/ and rename to superproject/path/to/, and rename / to /.git.

    Then you can use the git submodule deinit to remove the submodule:

    mv asubmodule asubmodule_tmp
    git submodule deinit -f -- a/submodule    
    rm -rf .git/modules/a/submodule
    
    # if you want to leave it in your working tree
    git rm --cached asubmodule
    mv asubmodule_tmp asubmodule
    

    I still want to be a submodule of superprojec

    Then its .git folder would be in superproject/.git/modules/

    submodule absorbgitdirs does not leave any choice:

    If a git directory of a submodule is inside the submodule, move the git directory of the submodule into its superprojects $GIT_DIR/modules path and then connect the git directory and its working directory by setting the core.worktree and adding a .git file pointing to the git directory embedded in the superprojects git directory.

    I don't see in git config any configuration that might move $GIT_DI R/modules.

    absorbgitdirs was introduced in commit f6f8586 for Git 2.12 (Q4 2016)
    Its tests shows it expects to use GIT_DIR/modules.

    Older Git (before Git 1.7.8, Oct. 2011) had a .git directly inside the submodule folder.

提交回复
热议问题