Restoring deleted submodules

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 :

  • Heroku Cannot GET /
  • GitHub Source view shows commit that does no longer exist
  • ssh issue on windows 7 (gitbash vs. windows cmd)
  • Is squashing commits into one best practice (for this particular workflow)?
  • How can I compare my local forked repository with changes that may have been made to the original?
  • What's the Windows command shell equivalent of bash's `true` command?
  • 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? ****
    

  • How do I fork multiple projects into one repository with git?
  • Git undo last commit
  • Setting automatic GIT deployment of PHP project
  • Trying to migrate to Github from Bitbucket, getting file size error
  • Git workflow two developers remotely, best practice?
  • How can I verify that a git project's release branch's fixes have all been merged into master?
  • One Solution collect form web for “Restoring deleted submodules”

    Initializing a git repo within dir2 (cd dir2; git init) doesn’t make dir2 a submodule.

    It just make dir2 a nested repo which will be ignored by any parent repo.
    Deleting dir2 means you have no direct way to retrieve its content.

    You could have done git submodule add /another/path/dir2, with dir2 a repo outside of dir1.
    Then it would have been possible to restore dir2.

    Git Baby is a git and github fan, let's start git clone.