Stash everything in Git including all submodules?
You can use foreach
to run a specific git command on each sub-module. For example to apply 'git stash' to every modules use this:
git submodule foreach 'git stash'
Similarly, the following command will checkout master
branch and then pull any updates from the remote source for each submodule.
git submodule foreach 'git checkout master; git pull'
Read more at: http://git-scm.com/book/en/v2/Git-Tools-Submodules
Warning: before Git .24 (Q4 2019), using "git submodule foreach git stash
" could lost local changes to submodules.
See commit 556895d (12 Oct 2019) by Jakob Jarmar (jarmar
).
(Merged by Junio C Hamano -- gitster
-- in commit bb52def, 18 Oct 2019)
stash
: avoid recursive hard reset on submodulesSigned-off-by: Jakob Jarmar
git stash
push does not recursively stash submodules, but if submodule.recurse is set, it may recursivelyreset --hard
them.Having only the destructive action recurse is likely to be surprising behaviour, and unlikely to be desirable, so the easiest fix should be to ensure that the call to
git reset --hard
never recurses into submodules.This matches the behavior of
check_changes_tracked_files,
which ignores submodules.