场景
开发工具IDE为IntelliJ IDEA,IDEA提项目至本地仓库会提.idea文件夹内容。其中是一些项目配置信息,含历史记录、版本控制等。这些内容可不上传git。此时需编.gitignore文件忽略无需提交文件。IDEA插件.ignore可做该事。
安装
File->Settings
- 左侧菜单找Plugins,点Browse repositories…
- 如图搜
.ignore
,点Install,装完重启IDEA即可
注意
按上法装完重启IDEA或报错。报错下载压缩包,选Install plugin from disk并重启IDEA即可。
使用
- 项目
右键->New ->.ignore file ->.gitignore file(Git)
;
- 先选Example user template,以后可手添需过滤文件,最后点Generate生成。然后发现被忽略文件名变灰,此时可提代码;
- 也可右键加文件到忽略名单。
规则
*.a # 忽略所有.a结尾的文件
!lib.a # 但lib.a除外
/TODO # 仅仅忽略项目根目录下的TODO文件,不包括subdir/TODO
build/ # 忽略build/目录下的所有文件
doc/*.txt # 会忽略doc/notes.txt但不包括doc/server/arch.txt
模板
# Built application files
*.apk
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
release/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
# google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
# Version control
vcs.xml
# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
# Signing configuration file (storePassword, etc)
keystore.properties
注意
- .gitignore只忽略原没被track文件,某些文件已被纳入版本管理则改.gitignore无效。可先删本地缓存(变未track状)后再提。
或git rm -r –cached filePath git commit -m "remove xx"
git rm -r –cached . git add . git commit -m "update .gitignore"
- 参数
-r
删文件夹及其子目录,–cached
删暂存区文件而不删工作区文件。第一种删某文件,第二种删所有暂存区文件,再加一遍,等同更新一遍。