8

Once I run

git update submodule

can I do anything to make it go back to the way it was before init and update?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user561638
  • 1,299
  • 3
  • 15
  • 26

3 Answers3

7

You say that you want to go back to before init and update, which would be the situation where the submodule is still present in .gitmodules, but is an empty directory which isn't registered in .git/config.

Suppose your submodule is called foo/bar, then you could do the following:

# Move the submodule out of your repository, just in case you have changes
# in there that you realise afterwards that you'd like to preserve:
mv foo/bar/ ~/backups/old-foo-bar/

# Recreate the submodule directory, but empty this time:
mkdir foo/bar/

# Remove all the config variables associated with that submodule:
git config --remove-section submodule.foo/bar
# Note that the submodule name is *without* the trailing slash
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
2

Try (with git1.8.3, April 22d 2013) a:

git submodule deinit

(See "How do I remove a Git submodule?")

This removes the whole submodule.<name> section from .git/config either for the given submodule(s)

You might have to delete the working tree for that submodule though.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

If you changes were commited, then you should be able to check the reflog:

git reflog

Once you find the change set you lost you can merge it back in.

If your changes were not commited, then they cannot be recovered.

drewag
  • 93,393
  • 28
  • 139
  • 128
  • What I wanted was a way to preserve the submodule, but just remove the populated files in my workspace. Turns out, I can just delete the directory and it doesn't affect the submodule in any way. So, in my case, my submodules are in a directory named projects. I can just remove projects/toolchain and the contents are gone, but git doesn't record the deletion. Thanks to everyone for trying this one. – user561638 Mar 22 '11 at 14:20