Suppose that I have a submodule dir1/dir2
(created via the steps shown below). How do I restore the submodule dir2
after having deleted it?
git submodule update
complains that the submodule does not exist, and git reset HEAD --hard
restores dir2
but not its contents. I am creating the submodule in the following way :
mkdir dir1
cd dir1/
mkdir dir2
cd dir2/
touch 1.txt
git init
git add 1.txt
git commit -m "test"
cd ..
git init
git submodule add ./dir2/
git commit -m "adding submodule"
rm -r dir2
**** Now how do I restore dir2 and its contents? ****
git submodule update --init
doesn't do the trick? – Lackfatal: repository 'dir1/dir2' does not exist
error message – Helpfulmkdir dir1/dir2
before thegit submodule update --init
? Also, what version of Git are you using? – Lackfatal: repository
. I guess this must be because the.git
files are missing from withindir1/dir2
– Helpfulgit version 2.1.3
. Butdir1/dir2
will have git files because I make it a repository (viagit init
from withindir2
) before I add it as a submodule todir1
(see commands above) – Helpful.gitmodules
file and have deleted the submodules repositories, try this script: gist.github.com/aroemen/5027030 – Discontinuance