git Git忽略目录中除子文件夹之外的所有内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18930103/
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 Ignore everything in a directory except subfolders
提问by nickel715
This is my folder structure:
这是我的文件夹结构:
data/
.gitignore
uploads/
.gitignore
I would like to commit the folders but not the files inside them.
我想提交文件夹而不是其中的文件。
So I add a .gitignore files in every folder with the following content:
所以我在每个文件夹中添加了一个 .gitignore 文件,内容如下:
# Ignore everything in this directory
*
# Except this file
!.gitignore
The problem is that *
matches also on directories so git tracks only data/.gitignore
问题是也*
匹配目录所以 git 只跟踪data/.gitignore
采纳答案by nickel715
The solution is quite easy, add !*/
to the .gitignore files and only files in the current folder will be ignored
解决方法很简单,添加!*/
到 .gitignore 文件中,只会忽略当前文件夹中的文件
# Ignore everything in this directory
*
# Except this file
!.gitignore
# Except folders
!*/
回答by kaiser
Please don't misuse.gitignore
files. Better stick to default ways to go on this, so later developers can quickly get into your project.
请不要滥用.gitignore
文件。最好坚持使用默认方式进行此操作,以便以后的开发人员可以快速进入您的项目。
- Add an empty
.gitkeep
file in the folders that you want to commit without the files Exclude the folders, but not the
.gitkeep
from your main.gitignore
file.folder/* !folder/.gitkeep
.gitkeep
在要提交的文件夹中添加一个空文件而不包含这些文件排除的文件夹,而不是
.gitkeep
从你的主.gitignore
文件。folder/* !folder/.gitkeep
This ignores all files in a folder, but not the .gitkeep
file. Now the folder will be commited with only the .gitkeep
file as content.
这会忽略文件夹中的所有文件,但不会忽略该.gitkeep
文件。现在该文件夹将仅以.gitkeep
文件作为内容提交。
回答by e18r
Try this:
尝试这个:
*.*
!.gitignore
!*/*