Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 352
Walt D Avatar asked Feb 09 '13 05:02

Walt D


People also ask

How do I update my submodule Sha?

In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.

What is the purpose of git filter branch `?

git-filter-branch can be used to get rid of a subset of files, usually with some combination of --index-filter and --subdirectory-filter .

What is git submodule update -- init?

The git submodule init command creates the local configuration file for the submodules, if this configuration does not exist. # add submodule and define the master branch as the one you want to track git submodule add -b master [URL to Git repo] git submodule init.


1 Answers

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.

like image 166
Walt D Avatar answered Oct 19 '22 23:10

Walt D