Skip to content

Commit ef4d0e5

Browse files
dougbarthschacon
authored andcommitted
Submodule gotcha when manually adding.
Don't append the trailing slash, otherwise, bad things will happen. Signed-off-by: Scott Chacon <schacon@gmail.com>
1 parent aa75e5b commit ef4d0e5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

text/34_Git_Submodules/1_Submodules.markdown

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,48 @@ others won't be able to clone the repository:
181181
Did you forget to 'git add'?
182182
Unable to checkout '261dfac35cb99d380eb966e102c1197139f7fa24' in submodule path 'a'
183183

184+
If you are staging an updated submodule for commit manually, be careful to not
185+
add a trailing slash when specifying the path. With the slash appended, Git
186+
will assume you are removing the submodule and checking that directory's
187+
contents into the containing repository.
188+
189+
$ cd ~/git/super/a
190+
$ echo i added another line to this file >> a.txt
191+
$ git commit -a -m "doing it wrong this time"
192+
$ cd ..
193+
$ git add a/
194+
$ git status
195+
# On branch master
196+
# Changes to be committed:
197+
# (use "git reset HEAD <file>..." to unstage)
198+
#
199+
# deleted: a
200+
# new file: a/a.txt
201+
#
202+
# Modified submodules:
203+
#
204+
# * a aa5c351...0000000 (1):
205+
# < Initial commit, submodule a
206+
#
207+
208+
To fix the index after performing this operation, reset the changes and then
209+
add the submodule without the trailing slash.
210+
211+
$ git reset HEAD A
212+
$ git add a
213+
$ git status
214+
# On branch master
215+
# Changes to be committed:
216+
# (use "git reset HEAD <file>..." to unstage)
217+
#
218+
# modified: a
219+
#
220+
# Modified submodules:
221+
#
222+
# * a aa5c351...8d3ba36 (1):
223+
# > doing it wrong this time
224+
#
225+
184226
You also should not rewind branches in a submodule beyond commits that were
185227
ever recorded in any superproject.
186228

0 commit comments

Comments
 (0)