How to rebase git submodule preserving references to submodule commits from git repository containing the submodule?

Vyacheslav Napadovsky

(Currently I'm fixing my old repositories before publishing.)

I already know how to rewrite commit author e-mail and name in git history.

I have a git project with submodules. I want to rewrite history of these submodules, but because I fast-forward these submodules during development, I want to modify links from main git repo pointing to some of these submodules commits to links pointing to new commits after submodule rebase. I.e. I need to rebase git submodule in conjunction with rebasing git repository containing this submodule. (Sorry, for too long text, I don't know how to describe that shorter.)

How to rewrite git submodule history in sync with git repository history containing the submodule?

VonC

As I mentioned in "Repository with submodules after rewriting history of submodule", there is no easy solution.

You will have to rewrite the history of your main repo with git filter-branch, looking for specific commits including a gitlink (special entry in the index)

You need first to establish a correspondence between the SHA1 of the submodule old history and the gitlinks used by your main repo

 cd /submodule/repo/just/rewritten/
 # the old history is still available in refs/original
 git -C /path/to/rewritten/repo for-each-ref --format="%(refname)" refs/original

 cd /main/repo
git for-each-ref --contains <SHA1> # SHA being a SHA1 from the old submodule history

Then you will need to replace

git filter-branch --prune-empty --tree-filter 'change_gitlink'

change_gitlink would be a script that would go into the submodule folder (hence --tree-filter, and not --index-filter), checkout the new SHA1 (from the new history of the submodule). The filter branch would commit the new repo state, including the new gitlink (because the submodule was checked out at the right new SHA1)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make an existing directory within a git repository a git submodule

Ignore new commits for git submodule

How do I move an existing Git submodule within a Git repository?

How to revert a Git Submodule pointer to the commit stored in the containing repository?

Git submodule from subdirectory?

How to change HEAD of git submodule

How to resolve git submodule conflict if submodule is not initialized

How to import python file from git submodule

How to update git submodule

git common submodule of submodule

How to exclude a specific git submodule from update?

Git How to discard changes to a submodule

How to correctly configure git submodule

Rebase git submodule and parent repo

Git Update Submodule in main repository

How to rename a git submodule

Git submodule shows new commits, submodule status says nothing to commit

how to work with git submodule in a new repository?

Older version of a git repository as a submodule

Cloning local Git repository containing a submodule with local branch

Update references to a submodule in parent repository after submodule's git history is re-written

a single directory containing git submodule and parent repository

python git-submodule importing from other git-submodule

Changing the remote repository of git submodule for all commits in git history

Is a Git submodule an independent repository?

Is it possible to add a submodule to a submodule from the top-level git repository?

How to delete a git submodule locally?

How to remove submodule changes from a git commit

git/submodule: detached ahead after update --rebase