过滤存储库时如何保留标记? [英] How do I preserve tags when filtering a repository?

查看:63
本文介绍了过滤存储库时如何保留标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有方法将存储库及其所有标记移动到另一个存储库的子目录中?

出于某种原因,一个项目被拆分为多个存储库。现在我们看到这不是一个热门的想法,并希望再次将它重新整合在一起。考虑子模块,但它们确实是一个项目,我们需要在它们之间移动大量文件。



假设我们有存储库A,B和C.需要一个项目作为子目录:

 项目/ 
A /
B /
C /

可以使用 git-filter-branch --tree过滤。完成,没问题。它甚至也正确地分行,这是一个惊喜。



问题是,A,B和C有标签,他们都需要转换,



这可以实现自动化吗?

解决方案

可以回答我自己的问题。将 - tag-name-filter cat 添加到 git-filter-branch 调用中。 - --all 会立即执行所有分支和标签,大大加快转换速度。

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

随着移动到subdir是我写的一个小程序,用于创建子目录并将文件移入其中。

 #!/ usr / bin / env perl 

使用Path :: Class;
使用autodie;

my $ subdir = shift;

mkdir $ subdir除非-d $ subdir;

my $ cwd = dir(。);
my @kids = grep {$ _ ne $ subdir} $ cwd-> children;
为我的$ dir(@kids){
重命名$ dir,dir($ subdir / $ dir) - >清理;
}

这些信息全部在git-filter-branch手册页中,但它是那种模糊的。


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 split into multiple repositories. Now we see that wasn't such a hot idea and want to bring it back together again. Submodules were considered, but they really are one project and we need to move a lot of files between them.

Let's say we have repository A, B and C. And we want one project with each of them as a subdirectory:

project/
    A/
    B/
    C/

That can be accomplished with git-filter-branch --tree-filter. Done, no problem. And it even does the branches correctly too, which was a pleasant surprise.

The trouble is, A, B and C have tags, and they all need to be converted, too.

Can this be automated?

解决方案

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.

这篇关于过滤存储库时如何保留标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆