git EGit 和 Eclipse 修改 .gitignore 文件,但不应该

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17748223/
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 08:48:25  来源:igfitidea点击:

EGit and Eclipse modifies .gitignore file but it should not

eclipsegiteclipse-pluginegit

提问by jefff35

I'm using Eclipse and EGit, but Eclipse modifies my .gitignorefile without me asking to do so. As soon as I open Eclipse the .gitignorefile is modified.

我正在使用 Eclipse 和 EGit,但 Eclipse 修改了我的.gitignore文件,而我没有要求这样做。一旦我打开 Eclipse,.gitignore文件就会被修改。

I've added some folders to .gitignore(through EGit) but removed them after, but Eclipse keeps adding removed lines to .gitignore.

我已经将一些文件夹添加到.gitignore(通过 EGit)但之后删除了它们,但是 Eclipse 不断向.gitignore添加删除的行。

  1. git checkout .gitignore, I get the good version of the file
  2. Then I go to Eclipse window
  3. Then I go back to terminal and issue: git status,
  4. I can see that .gitignore is now modified.
  1. git checkout .gitignore, 我得到了文件的好版本
  2. 然后我去Eclipse窗口
  3. 然后我回去终端和问题:git status
  4. 我可以看到 .gitignore 现在被修改了。

How can it be?

怎么会这样?

回答by robinst

By default, EGit automatically adds resources marked as "Derived" to .gitignore. A typical example is the binfolder in a Java project containing the compiled classes.

默认情况下,EGit 会自动将标记为“派生”的资源添加到.gitignore. 一个典型的例子是binJava 项目中包含编译类的文件夹。

You can disable this by going to Window > Preferences > Team > Git > Projects and deselect "Automatically ignore derived resources by adding them to .gitignore".

您可以通过转到“窗口”>“首选项”>“团队”>“Git”>“项目”并取消选择“通过将派生资源添加到 .gitignore 来自动忽略派生资源”来禁用此功能。

There was also a bug in EGit where it added entries when the Eclipse model and the filesystem were out-of-sync, see bug 421610(fixed for EGit 3.5).

EGit 中还有一个错误,它会在 Eclipse 模型和文件系统不同步时添加条目,请参阅错误 421610(已针对 EGit 3.5 修复)。