从 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
Remove .iml Files From GIT for Good
提问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
*.iml
to my project's.gitignore
file as well as each module's.gitignore
. I have tried both*.iml
and**/*.iml
- Used
git rm --cached app/app.iml
when 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
回答by Ahmed Hegazy
You have the right steps, but you need to organize them
你有正确的步骤,但你需要组织它们
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
*.iml
files likegit ls-files | grep "\.iml$" | xargs git rm --cached
Commit that change using
git commit -m "msg"
and after that, you can see all your*.iml
files as untracked files.- Add
*.iml
to your .gitignorefile and commit it in a separate commit or in the same previous commit.
git rm --cached <all_your_iml_files>
从远程存储库中删除所有这些。或者,您可以执行一个简单的命令来删除所有
*.iml
文件,例如git ls-files | grep "\.iml$" | xargs git rm --cached
使用提交更改
git commit -m "msg"
之后,您可以将所有*.iml
文件视为未跟踪的文件。- 添加
*.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 .gitignore
file 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 **/*.iml
will cover all iml files in all directories within the current working directory.
glob 语法**/*.iml
将覆盖当前工作目录中所有目录中的所有 iml 文件。