“This is the 28th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

The problem

In our daily development process, sometimes we will accidentally submit some unnecessary files to Git, such as some files in the project app.iml, configuration files under the idea folder, *.log, *.class files, and push to the remote server. At this time, I found that app.iml should not be managed by Git. After colleagues download this file, it will cause many problems such as project loading failure, incorrect loading and abnormal use. Then you add “app.iml” to the.gitignore file and try to ignore it. There is no way to ignore the file anymore. Because.gitignore only works on files that have never been committed. After many attempts, I found the following two methods. At this time, you can try to ignore the file by the following two methods.

You are advised not to perform the following operations on idea. You are advised to run the Git command

Method 1: Synchronize a local deletion to a remote repository:

  1. Make a backup before you do something, in case you make a mistake and delete the code that your colleagues or you have worked so hard to type.

  2. Git rm -r –cached directory_name git rm -r –cached directory_name git rm –cached app.iml

  3. Add the file to be ignored in.gitignore

  4. Commit and push the modified file to the server

  5. Pull the project back from Git.

Method 2 Delete the remote repository and then synchronize it to the local database:

  1. Delete the file directly from the remote repository

  2. Back up the local files first, then pull the remote branch

  3. In this case, ignore the local file has been deleted, and then copy the original backup file

  4. Never add the files you just copied to Git

  5. Add the file you just copied to the.gitignore file

  6. Then push it to the remote warehouse