简体   繁体   English

从存储库中删除特定文件夹

[英]Removing Specific Folders from a Repo

I have a repo I have cloned locally from TFS that I am about to push to our new VSTS instance.我有一个从 TFS 本地克隆的存储库,我将要推送到我们的新 VSTS 实例。

Folder structure like so;文件夹结构是这样的;

\A\AA1234\
\A\AA1235\
\A\AA1236\
\A\AAB237\
\A\AAB238\
\A\AAB239\
\B\BA1234\
\B\BA1235\
\B\BAG236\
\B\BAG237\
\B\BAG238\
\C\...
...

What I would like is to remove all projects of the format 2 letters followed by numbers and keep the ones with 3 letters followed by numbers (regex below).我想要的是删除格式为 2 个字母后跟数字的所有项目,并保留 3 个字母后跟数字的项目(下面的正则表达式)。

I was using the following command which I found here to remove individual folders;我正在使用我在此处找到的以下命令来删除单个文件夹;

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch -r FOLDERTOREMOVE" --prune-empty --tag-name-filter cat -- --all 

The problem is this doesn't seem to work for subfolders.问题是这似乎不适用于子文件夹。 I could substitute 'FOLDERTOREMOVE' above with 'A' and it would work (I have tested this with a smaller, test repo).我可以用 'A' 替换上面的 'FOLDERTOREMOVE' 并且它会起作用(我已经用一个较小的测试回购测试了这个)。 But it appears this command only works with top level folders.但似乎此命令仅适用于顶级文件夹。 I have tried the following to no success;我尝试了以下方法但没有成功;

AA1234
\AA1234
\A\AA1234
A\AA1234

Is there a way to make this command work for subfolders?有没有办法让这个命令对子文件夹起作用? I can then create a batch file to run for all the folders I would like to remove.然后我可以创建一个批处理文件来运行我想要删除的所有文件夹。

Option 2 would be when it comes to git push -u origin master , to somehow specify not to include a folder list/regex.选项 2 是当涉及git push -u origin master ,以某种方式指定不包含文件夹列表/正则表达式。

Option 3, I used git-tfs to clone from TFS.选项 3,我使用 git-tfs 从 TFS 克隆。 There is an --ignore-regex command which I tried (below) but it still seemed to pull down everything.我尝试了一个--ignore-regex命令(如下),但它似乎仍然拉下所有东西。 I am willing to rerun the clone if I can get this to only pull the folders I need.如果我可以让它只提取我需要的文件夹,我愿意重新运行克隆。

git-tfs clone --ignore-regex="\/[a-zA-Z]{1}\/[a-zA-Z]{2}\d" http://tfs:1234/MyTFS "$/MyTFSPath" --branches=none

REGEX正则表达式

\\.\\[a-zA-Z]{3}.*?\\
\\.\\[a-zA-Z]{2}[^a-zA-Z].*?\\

Any help would be greatly appreciated.任何帮助将不胜感激。

Believe I found the issue with the regex not working in my initial clone from TFS.相信我发现正则表达式的问题在我从 TFS 的初始克隆中不起作用。 It seems GIT TFS uses a different regex flavour than I was expecting.似乎 GIT TFS 使用了与我预期不同的正则表达式风格。

While I was using;在我使用时;

git-tfs clone --ignore-regex="\/[a-zA-Z]{1}\/[a-zA-Z]{2}\d" http://tfs:1234/MyTFS "$/MyTFSPath" --branches=none

This should have actually been;这实际上应该是;

git-tfs clone --ignore-regex="/[a-zA-Z]{1}/[a-zA-Z]{2}\d" http://tfs:1234/MyTFS "$/MyTFSPath" --branches=none

Note that the '/' do not need to be escaped with '\\' as I had expected.请注意,'/' 不需要像我预期的那样用 '\\' 转义。 From my tests this regex then works to exclude files/folders you don't wish to include in your clone.从我的测试中,这个正则表达式可以排除您不希望包含在克隆中的文件/文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM