Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git filter-branch remove all submodules from my repo

Hello I have successfully rewrote history and got the 5 folders I wanted to extract using git filter-branch -f --prune-empty --tree-filter 'rm -rf <all unwanted dirs>' and kept all git history.

The only remaining issue are submodules, I sill have commits doing

Subproject commit <hash>

and I want to completely remove ALL of those submodule commits from my git history, how can I accomplish this?

like image 832
Hausland Avatar asked Apr 21 '14 22:04

Hausland


People also ask

What does git filter branch do?

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

Does git pull pull submodules?

Pulling with submodules. Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .

How do I manage git submodules?

If you want to check for new work in a submodule, you can go into the directory and run git fetch and git merge the upstream branch to update the local code. Now if you go back into the main project and run git diff --submodule you can see that the submodule was updated and get a list of commits that were added to it.


1 Answers

I have done it with

git filter-branch -f --prune-empty --tree-filter '
    git submodule deinit -f .
    git rm -rf lib && rm -rf lib
    find . -name .gitmodules -delete' HEAD

Assuming that all of my submodules were located in lib directory

like image 170
seroperson Avatar answered Sep 21 '22 16:09

seroperson