Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why has git-filter-branch not rewritten tags?

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?

like image 435
Malcolm Box Avatar asked Oct 06 '11 10:10

Malcolm Box


People also ask

Does git filter branch rewrite history?

DESCRIPTION. Lets you rewrite Git revision history by rewriting the branches mentioned in the <rev-list options>, applying custom filters on each revision. Those filters can modify each tree (e.g. removing a file or running a perl rewrite on all files) or information about each commit.

Do git tags apply to all branches?

Yes! The difference between a branch name and a tag name is that a branch name is expected to move, and git will move it automatically in that "on a branch" case.

Do git tags belong to a branch?

Tags and branch are completely unrelated, since tags refer to a specific commit, and branch is a moving reference to the last commit of a history. Branches go, tags stay. So when you tag a commit, git doesn't care which commit or branch is checked out, if you provide him the SHA1 of what you want to tag.

Can git tags change?

We are required to delete/update branches or delete/update files etc. Similar to this, sometimes, we are required to update the tags in Git. Updating a tag will take your tag to another commit. For example, we can update the tag v1.


1 Answers

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.

like image 86
sehe Avatar answered Oct 15 '22 07:10

sehe