Recover Deleted Submodules

Suppose I have a submodule dir1/dir2(created using the steps shown below). How to restore a submodule dir2after removing it?

git submodule updatecomplains that the submodule does not exist, but git reset HEAD --hardrestores dir2, but not its contents. I create a submodule as follows:

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? ****
+4
source share
1 answer

Initializing a git repo in dir2( cd dir2; git init) does not make a dir2submodule.

Just create a dir2nested repo that will be ignored by any parent repo.
Removing dir2means that you have no direct way to retrieve its contents.

git submodule add /another/path/dir2, dir2 dir1.
dir2.

+2

Source: https://habr.com/ru/post/1569748/


All Articles