We have a main git repo in which we have added another repo as submodule. We have configured to ignore any changes to this submodule by setting ignore=all in the .gitmodules file with the expectation that any changes within the submodule (commits or files) never show up as changes when adding files to staging.
What we are observing is that even though the submodule doesn't show up as changed when we run git status, using git add -A adds the submodule as a change if there is difference in the commits in the submodule between the current branch and master.
Is there a way to avoid the submodule from being added to staging/commit when using git add or git commit -am?
The workaround is to use update-index -assume-unchanged.
git update-index --assume-unchanged path/to/submodule
You can issue this command for multiple sub modules.
You can use following script to add all submodules to the ignored index
grep 'path =' .gitmodules | awk '{print $3}' | xargs git update-index --assume-unchanged
(based on another answer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With