How do I preserve tags when filtering a repository?

前端 未结 1 1363
春和景丽
春和景丽 2021-02-04 10:45

Is there a way to move a repository, and all its tags, to be a subdirectory of another repository in an automated fashion?

For reasons, a project was sp

1条回答
  •  日久生厌
    2021-02-04 11:08

    I think I can answer my own question. Adding --tag-name-filter cat to the git-filter-branch call. -- --all does all the branches and tags at once speeding up the conversion considerably. Here's the full call.

     git filter-branch --tree-filter 'move-to-subdir $subdir' --prune-empty --tag-name-filter cat -- --all
    

    With move-to-subdir being a little program I wrote to make the subdirectory and move the files into it.

    #!/usr/bin/env perl
    
    use Path::Class;
    use autodie;
    
    my $subdir = shift;
    
    mkdir $subdir unless -d $subdir;
    
    my $cwd = dir(".");
    my @kids = grep { $_ ne $subdir } $cwd->children;
    for my $dir (@kids) {
        rename $dir, dir("$subdir/$dir")->cleanup;
    }
    

    This information is all in the git-filter-branch man page, but it's kind of obscured.

    0 讨论(0)
提交回复
热议问题