1. 创建或编辑 .gitignore 文件
# 如果还没有 .gitignore 文件
touch .gitignore #linux环境下
#Windows环境下,直接右键新建名为 .gitignore 的文件
2. 在 .gitignore 中添加要排除的文件夹
**# 排除单个文件夹
folder_to_exclude/或者使用通配符排除所有类似文件夹
*/folder_to_exclude/
排除所有名为 node_modules 的文件夹
node_modules/**
3. 如果文件夹已经被跟踪,需要先将其从 Git 中移除
**# 停止跟踪但保留本地文件
git rm -r --cached folder_to_exclude/提交更改
git add .
git commit -m "停止跟踪 folder_to_exclude 文件夹"**