2

I am attempting to split a large repo into multiple smaller ones. The goal is to split a folder and retain the tags in the process.

I have tried:

git filter-branch --prune-empty --subdirectory-filter my-folder develop

This correctly place my-folder at the root of the new project, and retained the tags. However checking out a tag resulted in seeing the entire old directory structure within the new repo.

So I tried:

git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter my-folder -- --branches=develop --tags

This results in the develop branch being there with the old directory structure, BUT when I checkout a tag I see the subdirectory correctly filtered to the root! So the tags are correct but not the develop branch. Basically it has the opposite problem to the first method.

I am at a loss as to why the second method did not work. I would really appreciate any pointers!

EDIT:

Trying this now:

git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter my-folder -- --all

Was hesitant as I expect that this will take quite a bit longer. This did take longer, but it mostly worked. What did not work? Well the older tags in which the folder had not yet been created were left in the repo and when checked out contained the full (very) old directory structure. I had to grep and delete all these tags. Still the repo is not as small as I wuold have expected...

Dennis
  • 3,683
  • 1
  • 21
  • 43

1 Answers1

2

As I mentioned in "Git commands that could break/rewrite the history", the old git filter-branch command is slowly being deprecated.

Using the new git filter-repo, that would be:

 git filter-repo --path my-folder/ --to-subdirectory-filter / -- refs develop

Then push that one branch to a new empty Git repository.

That should move the relevant tags correctly.

Abdollah
  • 4,579
  • 3
  • 29
  • 49
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I will give it a go presently. – Dennis Oct 21 '19 at 08:37
  • I can only access 2.22.0. Do you know if it works with that version? – Dennis Oct 23 '19 at 09:31
  • Indeed works with 2.22.0 but I am being hit with a bug related to python not being able to process non unicode strings (or something to that effect). I am in a relatively restrictive environment and am not able to fire up a linux image to solve this for myself unfortunately. This is on a git-for-windows install – Dennis Dec 17 '19 at 22:36
  • @Dennis OK. Note: for Git for Windows, you can install any version you want (no elevation privilege required). However, Git 2.24 does have a bug: https://stackoverflow.com/a/59383810/6309 – VonC Dec 18 '19 at 06:49
  • going to accept yours as the answer at this stage. It looks like I would need to get `2.23` (thanks for pointing out that bug!) as well as another version of filter-repo. I will give it a go again. – Dennis Dec 18 '19 at 10:36