diff --git a/text/34_Git_Submodules/1_Submodules.markdown b/text/34_Git_Submodules/1_Submodules.markdown index 39cd4108..f6149334 100644 --- a/text/34_Git_Submodules/1_Submodules.markdown +++ b/text/34_Git_Submodules/1_Submodules.markdown @@ -181,6 +181,48 @@ others won't be able to clone the repository: Did you forget to 'git add'? Unable to checkout '261dfac35cb99d380eb966e102c1197139f7fa24' in submodule path 'a' +If you are staging an updated submodule for commit manually, be careful to not +add a trailing slash when specifying the path. With the slash appended, Git +will assume you are removing the submodule and checking that directory's +contents into the containing repository. + + $ cd ~/git/super/a + $ echo i added another line to this file >> a.txt + $ git commit -a -m "doing it wrong this time" + $ cd .. + $ git add a/ + $ git status + # On branch master + # Changes to be committed: + # (use "git reset HEAD ..." to unstage) + # + # deleted: a + # new file: a/a.txt + # + # Modified submodules: + # + # * a aa5c351...0000000 (1): + # < Initial commit, submodule a + # + +To fix the index after performing this operation, reset the changes and then +add the submodule without the trailing slash. + + $ git reset HEAD A + $ git add a + $ git status + # On branch master + # Changes to be committed: + # (use "git reset HEAD ..." to unstage) + # + # modified: a + # + # Modified submodules: + # + # * a aa5c351...8d3ba36 (1): + # > doing it wrong this time + # + You also should not rewind branches in a submodule beyond commits that were ever recorded in any superproject.