Skip to contentSkip to conversation

git reset <tree-ish> <paths> of addition of a submodule?

DISCUSSION David Turner 1 participant 2 messages Nov 30, 2017

lore
Share & tools
lore
#0 lore raw

git submodule add https://my-git-repo blort
git commit -m 'add a submodule'
git reset HEAD^ blort

The reset deletes the gitlink, but does not delete the entry in .gitmodules. On one hand, this is exactly what the user asked for -- they wanted the path 'blort' to be changed in the index, and that's what they got. On the other hand, the behavior differs from git rm, and seems confusing: most folks don't want an entry in .gitmodules which doesn't correspond to a gitlink.

If reset isn't the right thing for me to do when I want to say "oops" about adding a submodule, then what is? I could do:
git reset HEAD^ blort .gitmodules
but what if I added two submodules and only wanted to undo the addition of one?

#1 lore raw
Quoted 11 lines · David Turner

git submodule add https://my-git-repo blort
git commit -m 'add a submodule'
git reset HEAD^ blort

The reset deletes the gitlink, but does not delete the entry in .gitmodules.  On one hand, this is exactly what the user asked for -- they wanted the path 'blort' to be changed in the index, and that's what they got.  On the other hand, the behavior differs from git rm, and seems confusing: most folks don't want an entry in .gitmodules which doesn't correspond to a gitlink.

Quoted 6 lines

If reset isn't the right thing for me to do when I want to say "oops" about adding a submodule, then what is?  I could do:
git reset HEAD^ blort .gitmodules
but what if I added two submodules and only wanted to undo the addition
of one?

Also, resetting the deletion of a submodule has an even worse issue -- you end up with a gitlink but no entry in .gitmodules.