Hacker News new | ask | show | jobs
by rgovostes 1913 days ago
I routinely encounter problems where the file structure on disk gets out of sync with the .gitmodules file, or one of the internal files inside .git, and I need to completely recreate my local repo.

I dislike having to warn in the README file, "somewhere in this repo are submodules, and you need to use this incantation to clone them."

I think you can now have the submodule reference point to a branch but it can't point to a tag, which is what I want most of the time.

And there's how `git status` just reports "modified content" without going into details.

1 comments

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.