git-svn --ignore-paths

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7668752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:00:19  来源:igfitidea点击:

git-svn --ignore-paths

git

提问by ae6rt

I'm struggling for a number of hours now with the --ignore-paths option to git-svn, in an attempt to fetch only certain tags from a large repository.

我现在正在使用 git-svn 的 --ignore-paths 选项挣扎了几个小时,试图从大型存储库中仅获取某些标签。

I want to start the fetch at dev, which looks like

我想在 dev 开始提取,看起来像

> svn ls http://192.168.0.2/svn/repo/corporation/dev
branches/
tags/
trunk/

The repository directory listing for the complete set of tags looks like this:

完整标签集的存储库目录列表如下所示:

> svn ls http://192.168.0.2/svn/repo/corporation/dev/tags
Acme-4.x/
Acme-5.0/
Acme-5.1/
Acme-5.2/
Acme-5.3/
Acme-5.4/
Acme-5.5/
Acme-5.6/
Acme-5.7/
Acme-5.8/
Acme-5.9/

I want to ignore all tags before Acme-5.5.

我想忽略 Acme-5.5 之前的所有标签。

I attempt to initialize and fetch thusly:

我尝试这样初始化和获取:

> git svn init  http://192.168.0.2/svn/repo/corporation/dev
> git config svn.authorsfile ../users.txt
> git svn fetch --ignore-paths="Acme-4.x|Acme-5.0|Acme-5.1|Acme-5.2|Acme-5.3|Acme-5.4"

Unfortunately, I still see fetches occuring in the Acme-4.x tag. The fetches are manifested on the console by telltale paths such as

不幸的是,我仍然看到 Acme-4.x 标签中发生了提取。提取通过指示路径显示在控制台上,例如

A       ACME4.4/source/database/mssql/components/functions/vssver.scc

I've tried a bunch of variations on the regex, including full paths to the tags I want to ignore, which after an hour or two turned into utter regex thrashing and desperation. I've provided the --ignore-paths option to git-svn-init, all to no avail.

我已经尝试了一系列正则表达式的变体,包括我想忽略的标签的完整路径,在一两个小时后变成了彻底的正则表达式颠簸和绝望。我已经为 git-svn-init 提供了 --ignore-paths 选项,但都无济于事。

Would someone be kind enough to comment on why the regex's are not suppressing fetches on the paths specified in the ignores-regex.

有人会很友好地评论为什么正则表达式没有抑制在 ignores-regex 中指定的路径上的获取。

Thanks.

谢谢。

回答by stucampbell

I was having this same problem today: my regexp would just never match... Make sure you know what the target paths actually look like. I was making an incorrect assumption about the structure of the paths that were being fed to my regexp.

我今天遇到了同样的问题:我的正则表达式永远不会匹配...... 确保你知道目标路径实际上是什么样子。我对提供给我的正则表达式的路径结构做出了错误的假设。

To find out what the paths look like, make git-svn output each path to the consoleas it tests them:

要找出路径的样子,请测试它们时让 git-svn 将每个路径输出到控制台

NOTE: Just in case, make a backup copy of the git-svn file first!

注意:为了以防万一,请先备份 git-svn 文件!

  1. Open the git-svn script in a text editor. My script was <git-dir>/libexec/git-core/git-svn.
  2. Locate the is_path_ignoredsubroutine.
  3. Add a printstatement above the first returnstatement, as follows...
  1. 在文本编辑器中打开 git-svn 脚本。我的脚本是 <git-dir>/libexec/git-core/git-svn.
  2. 找到is_path_ignored子程序。
  3. print在第一条语句上方添加一条语句return,如下...
sub is_path_ignored {
    my ($self, $path) = @_;

    print STDERR "$path\n"; //<-- **ADD THIS LINE**

    return 1 if in_dot_git($path);
    return 1 if defined($self->{ignore_regex}) &&
            $path =~ m!$self->{ignore_regex}!;
    return 0 unless defined($_ignore_regex);
    return 1 if $path =~ m!$_ignore_regex!o;
    return 0;
}

Now use git-svnagain with the --ignore-pathsswitch.

现在git-svn再次使用--ignore-paths开关。

I realised that instead of paths like trunk/bazit was actually using bar/trunk/baz

我意识到,而不是像trunk/baz它实际使用的路径bar/trunk/baz

So instead of

所以代替

--ignore-paths='^(?:trunk|branches|tags)/baz' 

I needed to use

我需要使用

--ignore-paths='^bar/(?:trunk|branches|tags)/baz'

Don't forget to remove the printstatement from the git-svn script.

不要忘记print从 git-svn 脚本中删除该语句。

回答by DarkPatronusLinX

I'm posting this for everyone, who was aslo trying to use --ignore-pathsfor fetching only specific branches/tags...

我正在为每个人发布这个,他们也试图使用--ignore-paths来只获取特定的分支/标签......

After a while struggling with --ignore-paths, which resulted in the following pattern to ignore all folders in branches folder, except folder branchname1and branchname2:

经过一段时间与--ignore-paths 的斗争,导致以下模式忽略分支文件夹中的所有文件夹,文件夹branchname1branchname2 除外

--ignore-paths='branches/(?!branchname1|branchname2)'

Howerver, the correct solution is hiding at the bottom of the GIT SVN documentation:

然而,正确的解决方案隐藏在GIT SVN 文档的底部:

It is also possible to fetch a subset of branches or tags by using a comma-separated list of names within braces. For example:

[svn-remote "huge-project"]
  url = http://server.org/svn
  fetch = trunk/src:refs/remotes/trunk
  branches = branches/{red,green}/src:refs/remotes/project-a/branches/*
  tags = tags/{1.0,2.0}/src:refs/remotes/project-a/tags/*

也可以通过在大括号内使用逗号分隔的名称列表来获取分支或标签的子集。例如:

[svn-remote "huge-project"]
  url = http://server.org/svn
  fetch = trunk/src:refs/remotes/trunk
  branches = branches/{red,green}/src:refs/remotes/project-a/branches/*
  tags = tags/{1.0,2.0}/src:refs/remotes/project-a/tags/*

So in your case, .git/configshould contain something like this:

所以在你的情况下,.git/config应该包含这样的内容:

tags = tags/{Acme-4.x,Acme-5.0,Acme-5.1,Acme-5.2,Acme-5.3,Acme-5.4}:refs/remotes/origin/tags/*

回答by Toughy

You might also just try:

您也可以尝试:

cat .git/config

on Linux, or:

在 Linux 上,或:

type .git\config

on Windows, from your new repository directory, to see the fetch URL, the branches and tags url.

在 Windows 上,从您的新存储库目录中查看获取 URL、分支和标签 url。

回答by luney

I have a similar problem and a partial Solution for my case .. .

我有一个类似的问题和我的案例的部分解决方案......

Context :
We have only one SVN repository for Meca, Hardware, Software team... the repository is a complete mess.. so I try to use regex to reduce the area to scan. After 1 day I just gave up.

上下文:
我们只有一个用于 Meca、硬件、软件团队的 SVN 存储库……存储库一团糟……所以我尝试使用正则表达式来减少要扫描的区域。1天后我就放弃了。

Finally I used the include-path option to scan only folder with "*Src*" inside. which speed up the scan. also use the option :
-r to reduce the history size you will get in local.
--no-minimize-url otherwise git-svn will scan the whole repository even if you specify the trunk and branch location.

最后,我使用 include-path 选项仅扫描内部带有“*Src*”的文件夹。从而加快扫描速度。还可以使用选项:
-r 来减少您将在本地获得的历史记录大小。
--no-minimize-url 否则 git-svn 将扫描整个存储库,即使您指定了主干和分支位置。

git svn clone 
-r11213:HEAD 
--prefix svn/
--no-minimize-url
--trunk=/trunk/dev/SW/Code/Controller1
--branches=/branches/SW_team/
--include-paths=.*Src.*
https://svnserver.compagny.com/Project1/
Controller1__git__

notice that right now i do not care of the Tags.

请注意,现在我不关心标签。

Hope it could help, even It's not the original question (5 years ago :-) )

希望它能有所帮助,即使这不是最初的问题(5 年前 :-) )



EDIT: I cannot add a comment so I comment the question here (not enough reputation point)

编辑:我无法添加评论,所以我在这里评论这个问题(没有足够的声望点)

1) --ignore-paths can be given for git svn [init/fetch or clone] (i do not know if there is a different behavior)
2) --ignore-paths expect a regex , be carefull the "." means any character. By chance the carater "." is also any character so regex=Acme-5.0 will match string="Acme-5.0" but also string="Acme-580", it should work anyway.

1) --ignore-paths 可以用于 git svn [init/fetch or clone] (我不知道是否有不同的行为)
2) --ignore-paths 期望一个正则表达式,小心“。” 表示任何字符。偶然的“卡拉特”。也是任何字符,因此 regex=Acme-5.0 将匹配 string="Acme-5.0" 但也匹配 string="Acme-580",无论如何它应该可以工作。

回答by Bludzee

Would someone be kind enough to comment on why the regex's are not suppressing fetches on the paths specified in the ignores-regex.

有人会很友好地评论为什么正则表达式没有抑制在 ignores-regex 中指定的路径上的获取。

This path

这条路

ACME4.4/source/database/mssql/components/functions/vssver.scc

was fetched despite the --ignore-pathsargument because it just didn't match the regex.

尽管有--ignore-paths争论,但仍被提取,因为它与正则表达式不匹配。

There is no -between "ACME" and "4.4" in this path. And if the regex is case-sensitive, "ACME" won't match "Acme".

-此路径中没有“ACME”和“4.4”之间。如果正则表达式区分大小写,“ACME”将不匹配“Acme”。

This should have worked better:

这应该工作得更好:

git svn fetch --ignore-paths="ACME4.x|ACME5.0|ACME5.1|ACME5.2|ACME5.3|ACME5.4"

Note that --ignore-pathstargets file names, not tags.

请注意,--ignore-paths目标文件名,而不是标签。



(I bet you solved the issue long ago - this post is 4 years old).

(我敢打赌你很久以前就解决了这个问题——这篇文章已经有 4 年历史了)。

回答by Joseph Winston

I've struggled with the exact same problem and started editing .git/config to explicitly list the branches or tags that I want.

我一直在努力解决完全相同的问题,并开始编辑 .git/config 以明确列出我想要的分支或标签。

That approach worked well until I came across a svn repository with lots of branches, so I duly added the ones I wanted and left out the ones I did not. But this failed with configuration file errors. Trial and error apparently shows that there is a limit either the number of branches in the config file or more likely the total number of characters between the opening { and closing }.

这种方法很有效,直到我遇到了一个有很多分支的 svn 存储库,所以我适当地添加了我想要的那些,而忽略了那些我没有的。但这因配置文件错误而失败。反复试验显然表明,配置文件中的分支数量或更有可能是开头 { 和结尾 } 之间的字符总数存在限制。

My life would be much easier if I could just build regexs.

如果我可以构建正则表达式,我的生活会容易得多。

回答by Dominic

I have been experiencing strange problems with --ignore-paths too. git-svn seems to ignore the entire regexp in some cases. I have seen the same regexp working on repos 1 and ignored on repos 2, where both repos have the same file structure, but different history.

我也遇到了 --ignore-paths 的奇怪问题。在某些情况下,git-svn 似乎忽略了整个正则表达式。我看到相同的正则表达式在 repos 1 上工作而在 repos 2 上被忽略,其中两个 repos 具有相同的文件结构,但不同的历史。

Although I don't see anything wrong with your regexp for your specific tree, I would recommend using the ^ caret at the beginning to specify the ignored paths starting at the root. This might help the rexexp parser speed-up the search and avoid issues where a match could also be found deep inside the trunk for example.

尽管我认为您的特定树的正则表达式没有任何问题,但我建议在开头使用 ^ 插入符号来指定从根开始的忽略路径。例如,这可能有助于 rexexp 解析器加快搜索速度,并避免在主干内部也可以找到匹配项的问题。

I would use something like --ignore-paths="^tags/Acme-(4|5.[0-4])"

我会使用类似 --ignore-paths="^tags/Acme-(4|5.[0-4])"