首页 > 解决方案 > gitignore 仅跟踪 2 个目录及其内容

问题描述

我想将我的 .gitignore 文件设置为仅跟踪 2 个目录以及其中的所有文件(有一些例外,如供应商)。我们为 cPanel 主机做了很多开发,发现用户目录中的所有其他 cPanel 目录也很难添加到本地 repo。

我们有 2 个目录要跟踪 public_html synergy

并想排除:synergy/vendor (composer) synergy/logs/* (仅此目录内的文件,不包括目录) public_html/uploads/*

我已经尝试了以下(从另一个stackoverflow问题中得到),但这似乎排除了所有子目录。

# Ignore everything
*

# But not these files...
!.gitignore
!synergy
!synergy/
!synergy/*
!public_html
!public_html/
!public_html/*

# Further specific excludes:
synergy/vendor
synergy/vendor/*
synergy/logs/*
/public_html/uploads/
/public_html/uploads/*

标签: git

解决方案


用于/**选择所有子目录

*
!.gitignore

!a
!b
!a/**
!b/**

推荐阅读