2

I have been using git filter-branch a lot to get rid of legacy files, however for a bare git repo I cannot figure out how I can rewrite my git history where one of my git submodules is removed.

I have a top-level repo "Donald" and below "Donald" I have four submodules "Huey", "Dewey", "Louie" and "Phooey" [1]. "Phooey" should never have been added - and unfortunately time passed where it was in.

Best reference I found is git filter-branch remove all submodules from my repo but it a bit too much.

[1] http://www.sullivanet.com/duckburg/phooey.htm :-)

Peter Toft
  • 565
  • 7
  • 19
  • Are you doing filter-branch on a branch that others are using? In that case, that might be a bit harmful, because since you are rewriting history you will rewrite commits that your team mates have checked out and are working on. In general, using filter-branch for removing just a few files seems like overkill in most situations. If I understand your situation correctly, the least intrusive, least complicated, and least unnecessary extra work for your collegues would be to delete the folder and commit the deletion. It is also more transparent in the history and people will see what's going on. – dvaergiller Apr 30 '18 at 11:45
  • @dvaergiller I fully understand, but I have strong business reasons to move in this direction – Peter Toft May 01 '18 at 08:34

1 Answers1

0

First, backup. Deinit and remove just one module:

git filter-branch -f --prune-empty --tree-filter '
    git submodule deinit -f -- path/to/module &&
    git rm -rf path/to/module || :
' HEAD &&
rm -rf .git/modules/path/to/module 
phd
  • 82,685
  • 13
  • 120
  • 165