Hacker News new | ask | show | jobs
by junon 1913 days ago
Moving submodules is indeed a PITA, but you don't have to recreate your whole repo.

The "correct" (albeit still annoying) way:

- git submodule deinit <path/to/submodule>

- rm -f <path/to/submodule>

- git submodule add ... new/path

In an emergency situation, you can almost always recover. I've not corrupted a repo in almost 10 years and I do some unspeakable things to them :)

To remove a module manually:

- git reset . (from root; NOT --hard)

- Remove the <path/to/submodule> from working directory.

- Remove entry from .gitmodules

- Remove entry from .git/config

- Remove (-rf) the folder .git/module/<path/to/submodule> directory (it follows the same structure as the working directory)

- git add -A .gitmodules <path/to/submodule> (Tab completion might not work but the command will)

This can be used to forcefully remove a submodule.

To remove all submodules without starting over (I've personally never needed this in the last X years):

- Remove all working directory paths for each submodule

- Remove .gitmodules

- Remove .git/modules/

- Remove any mention of submodules in .git/config

- git add -A

Usually the first manual one solves whatever problem you're facing.

EDIT: I have no idea how to format HN comments, sorry :| nothing I try works. Hope it's readable.