Can I unpopulate a Git submodule?

后端 未结 3 912
渐次进展
渐次进展 2021-02-08 23:57

Once I run

git update submodule

can I do anything to make it go back to the way it was before init and update?

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-09 00:56

    You say that you want to go back to before init and update, which would be the situation where the submodule is still present in .gitmodules, but is an empty directory which isn't registered in .git/config.

    Suppose your submodule is called foo/bar, then you could do the following:

    # Move the submodule out of your repository, just in case you have changes
    # in there that you realise afterwards that you'd like to preserve:
    mv foo/bar/ ~/backups/old-foo-bar/
    
    # Recreate the submodule directory, but empty this time:
    mkdir foo/bar/
    
    # Remove all the config variables associated with that submodule:
    git config --remove-section submodule.foo/bar
    # Note that the submodule name is *without* the trailing slash
    

提交回复
热议问题