This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.

Git is a familiar tool for developers, but you’ve certainly encountered the problem of intent.

After using Git to manage code, it is more convenient to submit and update code in Eclipse if you use Git plug-in in Eclipse. For maven projects, local projects often have local project configuration files that do not need to be submitted to the repository, such as the Target folder, the bin folder of the Maven project, etc. As shown below, in actual development we only need to submit: SRC, pom.xml,.gitignore, etc.

(.gitignore is a configuration file used to configure ignore files. It is recommended to submit it to the version library for easy use by other developers.)

In this case, how to commit only the files that need attention and ignore the unnecessary files or folders, so as to prevent local unnecessary files from being committed to the version library?

Git has two ways to ignore unnecessary files, one is the command method, the other is eclipse installation Git plug-in Settings.

Method 1: Configuration file method

  1. First create a hidden file “.gitignore “in the repository, select the local repository, right click” Git Bash Here “, and run the following command:
touch .gitignore
Copy the code

※ This configuration file is automatically generated in the project

It is highly recommended to use a configuration file to facilitate the use of others.

  1. Use a text editor such as editplus or notepad++ to enter the file or filename to ignore, as shown below:
##ignore this file##
/target/ 
.classpath
.project
.settings      
 ##filter databfile、sln file##
*.mdb  
*.ldb  
*.sln    
##class file##
*.com  
*.class  
*.dll  
*.exe  
*.o  
*.so  
# compression file
*.7z  
*.dmg  
*.gz  
*.iso  
*.jar  
*.rar  
*.tar  
*.zip  
*.via
*.tmp
*.err 
# OS generated files #  
.DS_Store  
.DS_Store?  
._*  
.Spotlight-V100  
.Trashes  
Icon?  
ehthumbs.db  
Thumbs.db  
Copy the code

Remark:

/target/ : Filter file Settings, which filter the folder

*. MDB, *. LDB, *. SLN: filters certain types of files

/ MTK /do.c, / MTK /if.h: indicates that specific files under a file are filtered

! *.c , ! / dir/subdir / :! Start indicates no filtering

*.[OA] Supports wildcard characters: Filters all files in the REPO whose extension name is. O or

This method ensures that no one can submit such files.

Method 2: Eclipse configuration

Eclipse installation Git plugin Settings: Click “Add Pattern” to Add files you want to filter. This method only ensures local commit filtering, but not remote repository.