如何让 Git 忽略 Rubymine 创建的 .idea 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9550437/
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
how to make Git ignore .idea files created by Rubymine
提问by AdamNYC
I use Rubymine for Rails projects. Very often, Rubymine makes changes in .idea/*
files that I don't care about. But it keeps preventing me from checking out new branches, and makes my version of .idea/
different from my coworkers.
我将 Rubymine 用于 Rails 项目。Rubymine 经常.idea/*
对我不关心的文件进行更改。但它一直阻止我检查新分支,并使我的版本.idea/
与我的同事不同。
We already added .idea/
to .gitignore
, but it keeps tracking changes in .idea
. How should I do this the right way?
我们已经添加.idea/
到.gitignore
,但它会不断跟踪 中的更改.idea
。我应该如何以正确的方式做到这一点?
Below is one of typical error messages I got:
以下是我收到的典型错误消息之一:
error: Your local changes to the following files would be overwritten by checkout:
.idea/workspace.xml
回答by Petr Syrov
Try git rm -r --cached .idea
in your terminal. It disables the change tracking.
git rm -r --cached .idea
在您的终端中尝试。它禁用更改跟踪。
回答by the_joric
just .idea/
works fine for me
刚.idea/
工作正常,我
回答by Daryn
Note that JetBrains recommends "If you decide to share IDE project files with other developers...", tracking all the .idea/*
files except the following three files:
需要注意的是JetBrains的建议:“如果你决定要与其他开发者共享IDE项目文件...”,跟踪所有的.idea/*
文件,除了以下三个文件:
- workspace.xml
- usage.statistics.xml
- tasks.xml
- 工作空间.xml
- 使用情况.statistics.xml
- 任务文件
So to follow their advice, you would add those 3 files to your .gitignore.
因此,按照他们的建议,您可以将这 3 个文件添加到您的 .gitignore 中。
Source:
来源:
If you decide to share IDE project files with other developers, follow these guidelines:
...
Here is what you need to share:
- All the files under .idea directory in the project root exceptthe workspace.xml, usage.statistics.xml, and tasks.xmlfiles which store user specific settings
- ...
How to manage projects under Version Control Systems(archive)
如果您决定与其他开发人员共享 IDE 项目文件,请遵循以下准则:
...
以下是您需要共享的内容:
- 项目根目录下 .idea 目录下的所有文件,除了存储用户特定设置的workspace.xml、usage.statistics.xml和tasks.xml文件
- ...
There's some additional notes on that page about which other files to gitignore for different specific jetbrains IDEs and builds.
该页面上还有一些附加说明,说明对于不同的特定 jetbrains IDE 和构建要 gitignore 哪些其他文件。
回答by Perception
Add .idea/*
to your exclusion list to prevent tracking of all .idea files, directories, and sub-resources.
添加.idea/*
到排除列表以防止跟踪所有 .idea 文件、目录和子资源。
回答by appsmatics
if a file is already being tracked by Git, adding the file to .gitignore won't stop Git from tracking it. You'll need to do git rm the offending file(s) first, then add to your .gitignore.
如果文件已经被 Git 跟踪,将文件添加到 .gitignore 不会阻止 Git 跟踪它。您需要先执行 git rm 有问题的文件,然后添加到您的 .gitignore。
Adding .idea/ should work
添加 .idea/ 应该可以
回答by GMarx
using git rm -r --cached .idea
in your terminal worked great for me. It disables the change tracking and unset a number of files under the rubymine folder (idea/) that I could then add and commit to git, thus removing the comparison and allowing the gitignore setting of .idea/
to work.
git rm -r --cached .idea
在您的终端中使用对我来说非常有用。它禁用更改跟踪并取消设置 rubymine 文件夹 (idea/) 下的许多文件,然后我可以将这些文件添加并提交到 git,从而删除比较并允许 gitignore 设置.idea/
工作。
回答by Gustavo Maimone
Close PHP Storm in terminal go to the project folder type
在终端中关闭 PHP Storm 转到项目文件夹类型
git rm -rf .idea; git commit -m "delete .idea"; git push;
Then go to project folder and delete the folder .idea
然后转到项目文件夹并删除文件夹.idea
sudo rm -r .idea/
Start PhpStorm and you are done
启动 PhpStorm 就完成了
回答by manavortex
In the rubymine gui, there is an ignore list (settings/version control). Maybe try disabling it there. I got the hint from their support guys.
在 rubymine gui 中,有一个忽略列表(设置/版本控制)。也许尝试在那里禁用它。我从他们的支持人员那里得到了提示。
回答by fosrias
Add .idea to ~/.gitignore_global and follow the instructions here to get .gitignore_global working:
将 .idea 添加到 ~/.gitignore_global 并按照此处的说明使 .gitignore_global 工作:
Then you don't have to ever add it to an individual .gitignore file.
然后您不必将其添加到单个 .gitignore 文件中。
回答by Promise Preston
While it's not been too long that I made the switch to Rubymine, I found it challenging ignoring .idea files of Rubymine from been committed to git.
虽然我切换到 Rubymine 的时间并不长,但我发现忽略 Rubymine 的 .idea 文件从提交到 git 是具有挑战性的。
Here's how I fixed it
这是我修复它的方法
If you've not done any staging/commit at all, or you just spinned up a new project in Ruby mine, then simply do this
如果你根本没有做任何暂存/提交,或者你只是在 Ruby mine 中启动了一个新项目,那么只需执行此操作
Option 1
选项1
Add the line below to the .gitignore file which is usually placed at the root of your repository.
将下面的行添加到 .gitignore 文件中,该文件通常位于存储库的根目录。
# Ignore .idea files
.idea/
This will ensure that all .idea files are ignored from been tracked by git, although they will still remain in your project folder locally.
这将确保所有 .idea 文件都不会被 git 跟踪,尽管它们仍将保留在您本地的项目文件夹中。
Option 2
选项 2
If you've however done some staging/commit, or you just opened up an existing project in Ruby mine, then simply do this
但是,如果您已经完成了一些暂存/提交,或者您刚刚在 Ruby mine 中打开了一个现有项目,那么只需执行此操作
Run the code in your terminal/command line
在终端/命令行中运行代码
git rm -r --cached .idea
This deletes already tracked .idea files in git
这会删除 git 中已跟踪的 .idea 文件
Next, include .idea/ to the .gitignore file which is usually placed at the root of your repository.
接下来,将 .idea/ 包含到 .gitignore 文件中,该文件通常位于存储库的根目录中。
# Ignore .idea files
.idea/
This will ensure that all .idea files are ignored from been tracked by git, although they will still remain in your project folder locally.
这将确保所有 .idea 文件都不会被 git 跟踪,尽管它们仍将保留在您本地的项目文件夹中。
Option 3
选项 3
If you've however done some staging/commit, or you just opened up an existing project in Ruby mine, and want to totally delete .idea files locally and in git, then simply do this
但是,如果您已经完成了一些暂存/提交,或者您刚刚在 Ruby mine 中打开了一个现有项目,并且想要在本地和 git 中完全删除 .idea 文件,那么只需执行此操作
Run the code in your terminal/command line
在终端/命令行中运行代码
git rm -r --cached .idea
This deletes already tracked .idea files in git
这会删除 git 中已跟踪的 .idea 文件
Run the code in your terminal/command line
在终端/命令行中运行代码
rm -r .idea
This deletes all .idea files including the folder locally
这将删除所有 .idea 文件,包括本地文件夹
Next, include .idea/ to the .gitignore file which is usually placed at the root of your repository.
接下来,将 .idea/ 包含到 .gitignore 文件中,该文件通常位于存储库的根目录中。
# Ignore .idea files
.idea/
This will ensure that all .idea files are ignored from been tracked by git, and also deleted from your project folder locally.
这将确保所有 .idea 文件都被 git 跟踪而忽略,并且也会从本地的项目文件夹中删除。
That's all
就这样
I hope this helps
我希望这有帮助