How to ignore unnecessary committed files using .ignore plugin in IntelliJ IDEA

I recently learned Git, and the IDE I am using is IntelliJ IDEA. I found that when IDEA submits a project to the local warehouse, it will also submit the contents of the .idea folder, which contains some project configuration information, including history. records, version control information, etc. You can not upload it to Git. 
At this time, you need to write a .gitignore file to ignore submitting these files. There is a plugin .ignore in IDEA that can do this for us.

Let's see how to install it first.

Click File->Settings 
write picture description here

Find Plugins in the left menu, click Browse repositories…

write picture description here

Search for .ignore, click Install, and you can use it happily after the installation is complete, but you have to restart IDEA before that 
write picture description here

However, the above method may report an error when IDEA is restarted after installation. . ('ཀ'"∠)_ Don't hit me, I don't know why. Then planB for you: https://plugins.jetbrains.com/idea/plugin/7495-ignore 
Go to this website to download the compressed package and select Install plugin from disk.
write picture description here

After restarting, it can really be used~!

Right-click on the project ->New ->.ignore file ->.gitignore file(Git) 
write picture description here 
first select the Example user template, you can add anything you want to filter in the future, ~ Finally click Generate to generate

write picture description here 
Then you will find that the ignored file names have become gray and woody! You can happily submit the code again~ 
write picture description here

You can also right-click the file to add it to the ignore list 
write picture description here


下面是一些.gitignore文件忽略的匹配规则:

*.a       # 忽略所有 .a 结尾的文件
!lib.a    # 但 lib.a 除外
/TODO     # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
build/    # 忽略 build/ 目录下的所有文件
doc/*.txt # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt

.gitignore can only ignore files that were not originally tracked. If some files have been included in version management, modifying .gitignore is invalid. Then the solution is to delete the local cache first (change it to an untracked state), and then submit it: 
Enter: 
git rm -r --cached filePath 
git commit -m "remove xx" 
or: 
git rm -r --cached . 
git add . 
git commit -m "update .gitignore"

To explain the next few parameters -r is to delete the folder and its subdirectories -cached is to delete the files in the staging area without deleting the files in the workspace, the first method is to delete a certain file, the second method takes All files in the temporary storage area are deleted and added again, which is equivalent to an update.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324683019&siteId=291194637