从 GIT 中永久删除 .iml 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35750673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:50:16  来源:igfitidea点击:

Remove .iml Files From GIT for Good

androidgitandroid-studiointellij-idea

提问by StuStirling

I am having issues with the .iml files generated by Android Studio. On a Gradle sync, they are regenerated meaning I then have to do a commit even if nothing has changed. I just want to make these files untracked.

我遇到了由 Android Studio 生成的 .iml 文件的问题。在 Gradle 同步中,它们会重新生成,这意味着即使没有任何更改,我也必须进行提交。我只是想让这些文件不被跟踪。

I have tried the following things.

我尝试了以下事情。

  • Added *.imlto my project's .gitignorefile as well as each module's .gitignore. I have tried both *.imland **/*.iml
  • Used git rm --cached app/app.imlwhen they appear in the staged files list. Even after doing this and committing it, they appear as staged again later on.
  • As suggested hereI added it to the Ignored Files in Settings under version control
  • 添加*.iml到我的项目.gitignore文件以及每个模块的.gitignore. 我曾经尝试都*.iml**/*.iml
  • 使用git rm --cached app/app.iml时,它们出现在上演的文件列表。即使在这样做并提交之后,它们也会在稍后再次上演。
  • 按照这里的建议我将它添加到版本控制下的设置中的忽略文件中

回答by Ahmed Hegazy

You have the right steps, but you need to organize them

你有正确的步骤,但你需要组织它们

  1. git rm --cached <all_your_iml_files>to remove all of them from the remote repository.

    Alternatively you can do a simple command to delete all the *.imlfiles like git ls-files | grep "\.iml$" | xargs git rm --cached

  2. Commit that change using git commit -m "msg"and after that, you can see all your *.imlfiles as untracked files.

  3. Add *.imlto your .gitignorefile and commit it in a separate commit or in the same previous commit.
  1. git rm --cached <all_your_iml_files>从远程存储库中删除所有这些。

    或者,您可以执行一个简单的命令来删除所有*.iml文件,例如 git ls-files | grep "\.iml$" | xargs git rm --cached

  2. 使用提交更改git commit -m "msg"之后,您可以将所有*.iml文件视为未跟踪的文件。

  3. 添加*.iml到您的.gitignore文件并在单独的提交中或在同一个先前的提交中提交。

回答by James T.

cd into project directory, git checkout and pull master branch

cd 进入项目目录,git checkout 并拉取 master 分支

cd /home/your_user/project_directory
git checkout master
git pull origin master

edit .gitignorefile to insert *.iml

编辑.gitignore要插入的文件*.iml

git rm --cached **/*.iml
git commit -a -m "rm all *.iml, update .gitignore"
git push origin master

I was working on another maven & Java git project using Idea IDE and it seems to add *.iml in many of the child directories.

我正在使用 Idea IDE 处理另一个 maven & Java git 项目,它似乎在许多子目录中添加了 *.iml。

The glob syntax **/*.imlwill cover all iml files in all directories within the current working directory.

glob 语法**/*.iml将覆盖当前工作目录中所有目录中的所有 iml 文件。