1. 创建/编辑 .gitignore 文件
在项目根目录下找到或创建 .gitignore 文件,添加以下内容:
#IDE 配置文件
.idea/
*.iml
.DS_Store
2. 如果 .idea 已经被 Git 追踪
如果 .idea 文件夹已经被 Git 追踪了,需要先停止追踪再忽略:
2.1 在终端执行以下命令
bash
git rm -r --cached .idea
git rm --cached *.iml
git commit -m "Remove .idea from git tracking"
2.2 提交 .gitignore 文件
bash
git add .gitignore
git commit -m "Add .gitignore to ignore IDE files"