Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I unpopulate a Git submodule?

Once I run

git update submodule

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

like image 206
user561638 Avatar asked Mar 21 '11 23:03

user561638


People also ask

Can I modify the submodule in git?

The submodule is just a separate repository. If you want to make changes to it, you should make the changes in its repository and push them like in a regular Git repository (just execute the git commands in the submodule's directory).

Is using git submodules a good idea?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.


1 Answers

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
like image 180
Mark Longair Avatar answered Oct 16 '22 03:10

Mark Longair