git-filter-repo icon indicating copy to clipboard operation
git-filter-repo copied to clipboard

Pick and choose submodules

Open BillyPocketNC opened this issue 4 years ago • 1 comments

Is there a way to pick and choose submodules? I have a .gitmodules file that has two submodules , but I only want to keep one of them.

BillyPocketNC avatar Jun 02 '21 17:06 BillyPocketNC

There is no scheme tailored to do this currently. You can specify --path (perhaps together with --invert-paths) to pick paths to keep or remove, which would remove the actual commits from the submodule, but that wouldn't clean up the .gitmodules file.

However, if you combined that with the lint-history contrib script, you could probably write a simple script that lint-history would call that could alter the .gitmodules file to match your preferences. It'd basically make it into a two step filtering process:

   git filter-repo --path unwanted-submodule --invert-paths
   contrib/filter-repo-demos/lint-history --relevant 'return filename == .gitmodules' YOUR_SCRIPT_NAME

The second command would repeatedly call

   YOUR_SCRIPT_NAME .gitmodules

in some special directory, with different versions of .gitmodules from history, and your script would be responsible for editing that file in place. Whatever changes you made to it would then be recorded in history for the commits that modified the .gitmodules file.

Does that help?

newren avatar Jun 06 '21 05:06 newren