从gitignore过滤文件和路径 [英] filtering of files and paths from gitignore

查看:199
本文介绍了从gitignore过滤文件和路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#找到所有未被(或子目录中的任何嵌套.gitignore文件)过滤的文件路径。这与PHP有关问题类似。我想知道是否有人知道这段代码是否已经在C#中可用(在C#中)。



更新:为了回答我想要的内容,它是如此我可以针对某些项目运行自己的小型定期备份(压缩结果),以增加安心性。最困难的部分是获得一个健壮的.gitignore解析器来获得过滤的文件路径(并排除其他文件路径),而不希望太过卷入了解规范是否其他人已经为我做了。

解决方案

很难在不知道你想要做什么的情况下提出建议(在构建脚本中使用它,以某种方式处理文件,在用户界面上查看它们等)



我在C#中找不到一个,但是这个JavaScript gitignore分析器没有太多的代码可以转换,它暴露了接受和一个 denies 方法来获取包含或忽略文件的列表。它有很好的文档记录,有测试,它使用的正则表达式在C#中的作用与在JavaScript中做的一样。





另请注意, Visual Studio的Git Source Control Provider插件在IDE中提供了正确的列表,以及一起复选框和提交某些文件的功能以及很多难以实现的功能注意:Git源代码管理提供程序是开源的(用C#编写的),您可以查看源代码 h ere ,但它可能比JavaScript项目涉及更多的逆向工程。



I would like to find all file paths that are not filtered by a .gitignore (or any nested .gitignore files within sub-directories) using C#. This is similar to the question here with regard to PHP. I'm wondering if someone knows if this code had already been made available (in C#) somewhere online.

UPDATE: To answer what I want this for, it is so I can run my own little periodic backup of my source files for certain projects (zipping the result), for added peace of mind. The hard part is getting a robust .gitignore parser to get the filtered file paths (and exclude the others), without wanting to become too embroiled in learning that spec if someone else already has done it for me.

解决方案

It's difficult to make suggestions without knowing exactly what you want to do with the list (use it in a build script, process the files in some way, just view them on a UI, etc.)

I couldn't find one in C#, but this JavaScript gitignore parser doesn't have a lot of code to convert and it exposes both an accepts and a denies method to get a list of included or ignored files. It is fairly well documented, has tests, and the regular expressions it uses would work just as well in C# as they do in JavaScript.

This answer would work from C#, provided you have Git installed on the machine where your C# code is running.

Also note that the Git Source Control Provider plugin for Visual Studio provides the list right in the IDE, along with the ability to check boxes and commit certain files together and a lot of other functionality that is difficult to do on the command line.

NOTE: The Git Source Control Provider is open source (written in C#) and you can view the source here, but it may be much more involved to reverse engineer than the JavaScript project.

这篇关于从gitignore过滤文件和路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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