Android Studio configures Git SVN to ignore files

When using Android Studio for version control, you often encounter situations where certain files need to be ignored, such as temporary files, files generated by compilation, etc. Although these files exist in the project, they do not want to be added to version control.

Set ignore files in Android Studio

In Android Studio, we can set ignore files by creating a .gitignore file. The .gitignore file is a plain text file that lists rules for files and folders to be ignored.

Here is the content of an example .gitignore file:

# 忽略所有的.iml文件
*.iml

# 忽略.gradle文件夹
.gradle

# 忽略local.properties文件
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml

# 忽略DS_Store文件
.DS_Store

# 忽略build文件夹
/build

/captures

.externalNativeBuild
.cxx
local.properties
In Android Studio, we can follow the following steps to create a .gitignore file. A new project will generate a .gitignore file by default:
  • Right-click in the root directory of the project and select New -> File.
  • Enter the file name ".gitignore" and click the OK button.
  • Open the .gitignore file and add rules for files and folders that need to be ignored.
Rules for ignoring files

In the .gitignore file, we can use some wildcards and special characters to describe files and folders that need to be ignored. Here are some commonly used rules:

  • *: Wildcard any number of characters.
  • ?: wildcard a single character.
  • /: Specify folders to ignore.
  • !: Negated, indicating that the file or folder will not be ignored.

Here are some common example rules:

  • *.class: Ignore all .class files.
  • build/: Ignore the build folder and its subfolders.
  • !src/main/java/: The src/main/java folder and its subfolders are not ignored.

The general configuration of the .gitignore file is as follows:

*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
.idea/
app/build/

Guess you like

Origin blog.csdn.net/Billy_Zuo/article/details/133701113