Home > Enterprise >  How do I discard modified content in git submodules?
How do I discard modified content in git submodules?

Time:12-12

I recently ran a git submodule init and update commits in my staging branch. This led to git downloading a bunch of changes from submodules that I do not want to put into staging and wish to discard completely.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   path-to/submodule1 (modified content)
        modified:   path-to/submodule2 (new commits,modified content)
    …


no changes added to commit (use "git add" and/or "git commit -a")

I'd like to discard all of these changes and and not add anything to my current branch. How do I do this?

CodePudding user response:

Since each submodule is its own Git repo, you can reset each one individually.

  1. Get rid of any local changes that are not committed: go into each submodule, and run git reset --hard

  2. Make sure each submodule is on the commit that the top-level Git repo wants, by running git submodule update at the top level.

  • Related