10

I needed to split my git repo into two parts. I used the steps shown here: Detach (move) subdirectory into separate Git repository

The command I used was:

 git filter-branch --subdirectory-filter ABC HEAD -- --all

which seemed to work fine and left me with ABC as the root.

However now if if I try to checkout a tag that existed before I split the repo:

 git checkout an-old-tagname

it's recreating the old directory structure - so recreating ABC as a subdirectory, along with XYZ1 and XYZ2.

I know that is how the repo really looked at that point in time - but I want the tag to refer to just the ABC bits, as if they'd been at the root back then. I thought that's what filter-branch was doing when it re-wrote history, but obviously I don't grok it properly.

How can I get the tags re-written so I can go back in time while still having ABC be the root of the repo?

Community
  • 1
  • 1
Malcolm Box
  • 3,968
  • 1
  • 26
  • 44

1 Answers1

20

You need to specify

--tag-name-filter cat

to rewrite tags as well

Now, you could do

git filter-branch --tag-name-filter cat ...other filter options... -- --tags

where ...other filter options... repeats the filters you previously applied.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    I can't rerun --subdirectory-filter again as the original subdir is now the root. Is there a way to get to the point where it is as if I'd run `--subdirectory-filter ... --tag-name-filter cat -- --tags` in the first place? – Malcolm Box Oct 06 '11 at 11:53
  • Nope, I'd expect you can run it 'again', as long as you run it against the tags. Remember, the tags were _NOT_ rewritten? You mention that yourself in the original post – sehe Oct 06 '11 at 12:45
  • @MalcolmBox I tweaked your tweak. Is it better like this? – sehe Oct 06 '11 at 22:48