Skip to content

Commit

Permalink
Submodule gotcha when manually adding.
Browse files Browse the repository at this point in the history
Don't append the trailing slash, otherwise, bad things will happen.

Signed-off-by: Scott Chacon <schacon@gmail.com>
  • Loading branch information
dougbarth authored and schacon committed Dec 21, 2008
1 parent aa75e5b commit ef4d0e5
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions text/34_Git_Submodules/1_Submodules.markdown
Expand Up @@ -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 <file>..." 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 <file>..." 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.

Expand Down

0 comments on commit ef4d0e5

Please sign in to comment.