Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore Git submodule after deleting it?

Tags:

git

github

I accidentally deleted a submodule directory/repository. After doing git submodule init i tried running git submodule update which gives me the following error:

fatal: Not a git repository: ../../.git/modules/externals/foo

Unable to find current revision in submodule path 'externals/foo'

Can somebody please tell me what i am doing wrong?

EDIT: I deleted the submodule directory, I can clone the submodule repository for which the link is in .gitmodules, but I read somewhere that i can completely delete submodules by deleting the .git/modules/externals folder which i deleted (I dont know if this was right thing to do) anyway i downloaded the repository and pasted on the location where the submodule is supposed to exist but that is now the correct way. git submodule gives the following output:

+244d6addc83d1cc801ff1880f71574d3fcc6b77e externals/foo (heads/master)

like image 783
DarthSpeedious Avatar asked Aug 24 '15 11:08

DarthSpeedious


People also ask

How do I undo a submodule change?

Move into the submodule's directory, then do a git reset --hard to reset all modified files to their last committed state. Be aware that this will discard all non-committed changes.

Where are submodules stored?

A submodule can be located anywhere in a parent Git repository's working directory and is configured via a . gitmodules file located at the root of the parent repository. This file contains which paths are submodules and what URL should be used when cloning and fetching for that submodule.

How do you fix a dirty submodule?

You can fix it by: either committing or undoing the changes/evolutions within each of your submodules, before going back to the parent repo (where the diff shouldn't report "dirty" files anymore). To undo all changes to your submodule just cd into the root directory of your submodule and do git checkout .

How do I copy a submodule to a repo?

The list of steps required to clone a Git repository with submodules is: Issue a git clone command on the parent repository. Issue a git submodule init command. Issue a git submodule update command.


1 Answers

I recovered my working copy using comment made by @UweGeuder:

git submodule deinit -f .
git submodule update --init
like image 69
fgiraldeau Avatar answered Oct 11 '22 09:10

fgiraldeau