git忽略除一个扩展名和文件夹结构以外的所有文件

编程入门 行业动态 更新时间:2024-10-24 02:00:45
本文介绍了git忽略除一个扩展名和文件夹结构以外的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的.gitignore:

This is my .gitignore:

#ignore all kind of files * #except php files !*.php

我只想忽略除.php文件以外的所有类型的文件,但是有了.gitignore,我也忽略了文件夹...

All I want is to ignore all kind of files except the .php ones, but with this .gitignore I'm also ignoring folders...

是否有一种方法可以告诉git接受我的项目文件夹结构,同时仅跟踪.php文件?

Is there a way to tell git to accept my project folder structure while keeping the track only of the .php files?

似乎现在我无法将文件夹添加到我的仓库中了:

It seems like now I can't add folders to my repo:

vivo@vivoPC:~/workspace/motor$ git add my_folder/ The following paths are ignored by one of your .gitignore files: my_folder Use -f if you really want to add them. fatal: no files added

推荐答案

这很简单,只需在.gitignore

#ignore all kind of files * #except php files !*.php !my_folder

最后一行将特别注意my_folder,并且不会忽略其中的任何php文件;但是由于*的第一个模式,其他文件夹中的文件仍将被忽略.

The last line will take special care of my_folder, and will not ignore any php files within it; but files within other folders will still be ignored because of the first pattern of *.

编辑

我想我误解了你的问题.如果要忽略除.php文件以外的所有文件,可以使用

I think I misread your question. If you want to ignore all files except .php files, you can use

#ignore all kind of files *.* #except php files !*.php

这不会忽略任何没有扩展名的文件(例如:如果您具有README而不是README.txt),并且将忽略名称中带有.的任何文件夹(例如:目录名为module.1).

This will not ignore any file which doesn't have an extension (example: if you have README and not README.txt ), and will ignore any folder with a . in its name (example: directory named module.1).

FWIW, git无法跟踪目录,因此无法为目录和文件指定忽略规则

FWIW, git doesn't track directories, and hence there is no way to specify ignore rules for directory vs file

更多推荐

git忽略除一个扩展名和文件夹结构以外的所有文件

本文发布于:2023-10-31 12:55:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:扩展名   文件夹   结构   文件   git

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!