git-svn clone 忽略文件夹的路径正则表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15502284/
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
git-svn clone ignore-paths regular expression for folders
提问by zapping
Am trying to do a git-svn clone to import all the files in SVN to GIT. The command that was given was this;
我正在尝试进行 git-svn 克隆以将 SVN 中的所有文件导入到 GIT。给出的命令是这样的;
git svn clone --stdlayout --ignore-paths='(/cache|/tmps|/file/conf/setting.xml)' --authors-file=../authors.txt file:///svnFolder/local-repos/PRG PRG.git
The above clones but the issue is it ignores all the files and folder that has cache and tmps. Like for instance it ignores even these
上面的克隆但问题是它忽略了所有具有缓存和 tmps 的文件和文件夹。例如,它甚至会忽略这些
new/folder/cache
meta/files/sets/tmps.html
Can anybody please help me out to set the regular expression to give in the ignore-paths to ignore files and subdirectories that is there in the root folder's cache and tmps directories.
任何人都可以帮我设置正则表达式以在忽略路径中给出忽略根文件夹的缓存和 tmps 目录中的文件和子目录。
回答by Russ Watson
Your ignore paths regex is too general. The regular expression provided is run on a full path. For example, if your repository layout is:
您的忽略路径正则表达式太笼统了。提供的正则表达式在完整路径上运行。例如,如果您的存储库布局是:
svn_root/path/to/your_project
And then has a standard layout of trunk, branches, and tags, a set of sample path lines that gets evaluated might be:
然后有一个标准的主干、分支和标签布局,一组被评估的示例路径线可能是:
svn_root/path/to/your_project/trunk/new/folder/cache
svn_root/path/to/your_project/trunk/meta/files/sets/tmps.html
svn_root/path/to/your_project/trunk/file/conf/setting.xml
svn_root/path/to/your_project/trunk/cache/...
svn_root/path/to/your_project/trunk/tmps/...
Lets start by analyzing the regex you provided as part of the ignore-paths parameter:
让我们首先分析您作为 ignore-paths 参数的一部分提供的正则表达式:
'(/cache|/tmps|/file/conf/setting.xml)'
- The surrounding parentheses means that the expression within should be capturing.
- The pipes, or alternation, means to evaluate each expression on the target string out of several possible expressions
- Each expression is very straight forward, but lets analyze each:
- /cache
- Find a literal character "/"
- Find a literal character "c"
- Find a literal character "a"
- Find a literal character "c"
- Find a literal character "h"
- Find a literal character "e"
- /tmps
- Find a literal character "/"
- Find a literal character "t"
- Find a literal character "m"
- Find a literal character "p"
- Find a literal character "s"
- /file/conf/setting.xml
- Find a literal character "/"
- Find a literal character "f"
- Find a literal character "i"
- Find a literal character "l"
- Find a literal character "e"
- Find a literal character "/"
- Find a literal character "c"
- Find a literal character "o"
- Find a literal character "n"
- Find a literal character "f"
- Find a literal character "/"
- Find a literal character "s"
- Find a literal character "e"
- Find a literal character "t"
- Find a literal character "t"
- Find a literal character "i"
- Find a literal character "n"
- Find a literal character "g"
- Match (almost) any character
- Find a literal character "x"
- Find a literal character "m"
- Find a literal character "l"
- /cache
- 周围的括号意味着其中的表达式应该是 capture。
- 管道或交替,意味着从几个可能的表达式中计算目标字符串上的每个表达式
- 每个表达式都非常简单,但让我们分析每个:
- /缓存
- 查找文字字符“/”
- 查找文字字符“c”
- 查找文字字符“a”
- 查找文字字符“c”
- 查找文字字符“h”
- 查找文字字符“e”
- /tmps
- 查找文字字符“/”
- 查找文字字符“t”
- 查找文字字符“m”
- 查找文字字符“p”
- 查找文字字符“s”
- /file/conf/setting.xml
- 查找文字字符“/”
- 查找文字字符“f”
- 查找文字字符“i”
- 查找文字字符“l”
- 查找文字字符“e”
- 查找文字字符“/”
- 查找文字字符“c”
- 查找文字字符“o”
- 查找文字字符“n”
- 查找文字字符“f”
- 查找文字字符“/”
- 查找文字字符“s”
- 查找文字字符“e”
- 查找文字字符“t”
- 查找文字字符“t”
- 查找文字字符“i”
- 查找文字字符“n”
- 查找文字字符“g”
- 匹配(几乎)任何字符
- 查找文字字符“x”
- 查找文字字符“m”
- 查找文字字符“l”
- /缓存
With your regular expression analyzed, lets walk through the sample paths given above with your expressions:
分析您的正则表达式后,让我们通过您的表达式浏览上面给出的示例路径:
String to evaluate:
要评估的字符串:
svn_root/path/to/your_project/trunk/new/folder/cache
- Loop through each character looking for a literal "/", followed by "c", etc... until a complete match is found with your first sub-expression "/cache". This path is ignored.
- 循环遍历每个字符以查找文字“/”,然后是“c”等......直到找到与您的第一个子表达式“/cache”的完整匹配。该路径被忽略。
String to evaluate:
要评估的字符串:
svn_root/path/to/your_project/trunk/meta/files/sets/tmps.html
- Loop through each character looking for a literal "/", followed by "c", etc... No match is found
- Loop through each character looking for a literal "/", followed by "t", etc... until a complete match is found with your second sub-expression "/tmps". This path is ignored.
- 循环遍历每个字符,查找文字“/”,后跟“c”等......未找到匹配项
- 循环遍历每个字符以查找文字“/”,然后是“t”等,直到找到与您的第二个子表达式“/tmps”的完整匹配。该路径被忽略。
String to evaluate:
要评估的字符串:
svn_root/path/to/your_project/trunk/file/conf/setting.xml
- Loop through each character and evaluate against the first sub-expression. No match is found
- Loop through each character and evaluate against the second sub-expression. No match is found
- Loop through each character and evaluate against the last sub-expression. Match is found. This path is ignored
- 循环遍历每个字符并针对第一个子表达式进行评估。未找到匹配项
- 循环遍历每个字符并针对第二个子表达式进行评估。未找到匹配项
- 循环遍历每个字符并针对最后一个子表达式进行评估。找到匹配。此路径被忽略
From here, you can probably see why the following two are also ignored. One of the sub expressions matches a portion of each path:
从这里,你大概可以看到为什么下面两个也被忽略了。子表达式之一匹配每个路径的一部分:
svn_root/path/to/your_project/trunk/cache/...
svn_root/path/to/your_project/trunk/tmps/...
There are several ways to solve this problem, but if you are only trying to ignore a couple of specific directories in the trunk, you could modify your expression as follows:
有多种方法可以解决此问题,但如果您只想忽略主干中的几个特定目录,则可以按如下方式修改您的表达式:
'(trunk/cache|trunk/tmps|/file/conf/setting\.xml)'
It really depends on what you want to do, which specific paths you want to ignore. If you need more help, if you could clarify in detail as to how your repository is laid out and which directories are to be ignored.
这实际上取决于您想要做什么,您想要忽略哪些特定路径。如果您需要更多帮助,请详细说明您的存储库的布局方式以及要忽略的目录。
回答by uml?ute
how about adding a start-of-line marker?
添加行首标记怎么样?
... --ignore-paths='^(/cache|/tmps|/file/conf/setting.xml)' ...