Search code examples
gitgit-submodules

How to git reset --hard HEAD^ root of repo without affecting submodules


After making a temporary commit to the root of a repo, which has submodules, I haphazardly ran git reset --hard HEAD^ with the intention of just deleting said commit on the master's root - but to my dismay affect all submodule repos too....

I just wanted to delete the head commit on the root repo.

Is there a better/safer way to accomplish this task without affecting the submodule repos ?


Solution

  • The default default for git reset is --no-recurse-submodules (as is true for checkout / switch as well). However, if you've set recursion to be on by default by configuring submodule.recurse to true or 1 or otherwise enabled, you can always pass an explicit --no-recurse-submodules option to override your override. You can also run git -c submodule.recurse=0, as noted in the git config documentation.