How do I use 'git filter-branch' to update the SHA of a submodule?

Let’s assume that I have two Git repositories, A and B. B is a submodule of A.

For the sake of simplicity, let’s also assume that I have a magic function, get_sha_B that, given an SHA commit from A, returns the desired SHA commit of B.

How do I run filter-branch on repo A such that each commit of repo A is rewritten to point to the desired commit of repo B, as returned by get_sha_B?

Thank you!

  • Git submodule update from post-receive hook
  • git: list of all changed files including those in submodules
  • Git: How to find out if fetching from a remote updated my submodules?
  • How to switch submodule branch based on superproject branch
  • un-submodule a git submodule
  • Convert Git submodule to subtree
  • Projects within projects using Git
  • use git submodule with read-only access
  • One Solution collect form web for “How do I use 'git filter-branch' to update the SHA of a submodule?”

    Figured it out! I’m going to answer my own question here:

    I can use git update-index in conjunction with git filter-branch --index-filter.

    Here’s how to call update-index to modify the commit SHA of a submodule:

    git update-index --cacheinfo 160000 88e6a302c42840440f9faac73f27efc6a3e0c1a6 pathto/mysubmodule
    

    As best as I understand it, the 160000 is a magic number in Git used to identify a submodule.

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