How to update git submodule who's history was rewritten

Say I have a git submodule already setup, and the upstream commit history has rewritten (for example a rebase squash was preformed).

Say the commit my submodule head is set to no longer exits. So I want to set the head hash submodule’s repo’s head. How do I do that?

  • Proper git etiquette for users working in mostly-isolated branches?
  • Commit Related to changes is there but the changes are not reflected in the repo , why does this happen?
  • Centralized GIT workflow/deployment - Repository Initialization and Feature Branches
  • Are there any free version control hosting applications I can host myself?
  • git push fails: RPC failed; result=22, HTTP code = 411
  • how to exclude typescript compiled files from git
  • git pre-receive (push) hook detect if a merge was done in a specific file
  • Git push failed,could not resolve host
  • Can I return a message from a python git pre-receive hook prefixed error: instead of remote:
  • Gitlab 7.3.2 Permission Denied (publickey)
  • How do I manage conflicts with git submodules?
  • Where does Git save user's secret tokens by default?
  • One Solution collect form web for “How to update git submodule who's history was rewritten”

    You can simply go in the submodule, do a git fetch, and checkout the HEAD you need.

    cd mysubmodule
    git fetch
    git checkout origin/abranch
    

    Then you go back to the parent repo, add and commit that new submodule SHA1 entry.

    Note that you also can convert a submodule in order to follow the latest commits of a branch.
    In that case, a simple:

    git submodule update --remote
    

    would be enough.

    Git Baby is a git and github fan, let's start git clone.