#!/bin/bash# Git pre-commit hook: Discards all changes in submodules before committing. (.git/hooks/pre-commit)set -eecho "Discarding all changes in submodules before commit..."# Reset and clean all submodules recursivelygit submodule foreach --recursive ' git reset --hard git clean -fdx'# Unstage any superproject submodule pointer updates, so submodule state never changesif [ -f .gitmodules ]; then git config --file .gitmodules --get-regexp path | awk "{print \\$2}" | while read submodule do if git diff --cached --name-only | grep -q "^$submodule"; then git reset HEAD "$submodule" fi donefiecho "All submodule changes have been discarded and unstaged."