git Git忽略Eclipse中的特定文件

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

Git ignore a specific file in Eclipse

eclipsegitegit

提问by Mistalis

I guess this kind of question has been asked many times (and I've seen several questionson SO dealing with this subject) but I still have a problem to ignore a file in my Git.

我想这种问题已经被问过很多次了(我已经看到了几个关于 SO 处理这个主题的问题)但是我仍然有一个问题要忽略我的 Git 中的文件。

The structure of my projectlooks like this:

我的项目的结构是这样的:

myProject/
    .gitignore
    src/test/java/packageName/
        Main.java

I would like to ignore Main.java(the file is different between each user).

我想忽略Main.java(每个用户之间的文件不同)。



.gitignorefile

.gitignore文件

.settings
.project
.classpath
target/
test-output/
node_modules/**
.orig


I've tried:

我试过了:

  • Adding src/test/java/packageName/Main.javato my .gitignore.

  • Creating a .gitignorefile in src/test/java/packageName/that just contains Main.java.

  • 添加src/test/java/packageName/Main.java到我的.gitignore.

  • .gitignoresrc/test/java/packageName/其中创建一个仅包含Main.java.

Both solutions have no effect: I still see Main.javain the Git Staging view after restarting Eclipse.

两种解决方案都没有效果:Main.java重新启动 Eclipse 后,我仍然在 Git Staging 视图中看到。



I guess the solution is simple, but I'm stuck on it for several hours, and I hope you can help me.

我想解决方案很简单,但我坚持了几个小时,希望你能帮助我。

Thanks! :-)

谢谢!:-)

UPDATE

All Git users have Main.java, but the class is different from one person to another (user name hardcoded in the class).

I want this class to be present on the HEAD branch (so that new developers can recover it), but each developer can have a local version (invisible in Git Staging).

更新

所有 Git 用户都有Main.java,但班级因人而异(用户名硬编码在班级中)。

我希望这个类出现在 HEAD 分支上(以便新开发人员可以恢复它),但每个开发人员都可以有一个本地版本(在 Git Staging 中不可见)。

回答by BartBog

Your problem is probably that Main.java is already in your index. The solution

您的问题可能是 Main.java 已经在您的索引中。解决方案

First make it disappear

首先让它消失

git rm src/test/java/packageName/Main.java

then add it to your gitignore

然后将它添加到你的 gitignore

echo "src/test/java/packageName/Main.java" >> .gitignore

now commit these changes

现在提交这些更改

git add .gitignore
git commit -m "please ignore me!"

And it should work :-)

它应该工作:-)

You can now recreate your Main.java and it should no longer appear in git status.

您现在可以重新创建 Main.java 并且它不应再出现在git status.

回答by Swarit Agarwal

Able to achieve it in Eclipse Oxygen. Here step follows.

能够在 Eclipse Oxygen 中实现它。下面是步骤。

  1. Enable "Automatic Ignore" .ignore file from window-> preference. enter image description here

  2. Right Click on file/folder to ignore. For example right click on target folder(contains .classfile). Team -> Ignore

  3. Go to Staging view, you will see .ignorefile generate.
  4. Right click on .ignorefile and ignore that again.
  1. 从窗口-> 首选项启用“自动忽略”.ignore 文件。 在此处输入图片说明

  2. 右键单击要忽略的文件/文件夹。例如右键单击目标文件夹(包含.class文件)。团队 -> 忽略

  3. 转到 Staging 视图,您将看到 。忽略文件生成。
  4. 右键单击 。忽略文件并再次忽略它。

回答by Tainoor

For disappearing auto-generated compiled .class like files from Git Staging view, Please follow following steps in eclipse.

要从 Git 暂存视图中消失自动生成的已编译的 .class 类文件,请在 eclipse 中按照以下步骤操作。

  1. Refresh Repository
  2. Open navigator perspective (You can search this in perspective).
  3. Now look for .gitignore file in the project directory if not present you can create this file in the project directory.
  4. add the following entries to the .gitignore file -
  1. 刷新存储库
  2. 打开导航器透视图(您可以在透视图中搜索)。
  3. 现在在项目目录中查找 .gitignore 文件,如果不存在,您可以在项目目录中创建此文件。
  4. 将以下条目添加到 .gitignore 文件中 -

/.class

/。班级

/bin/

/斌/

OR

或者

.class

。班级

bin/

仓/

  1. Now save the .gitignore file and refresh the repository or eclipse.
  1. 现在保存 .gitignore 文件并刷新存储库或 eclipse。

The unwanted files are will be disappeared.

不需要的文件将消失。

回答by Jeyhun

In eclipse where all the projects names are placed right next to there's small face down arrow ?? click on it then uncheck Class resources Then you are good to go

在 Eclipse 中,所有项目名称都放在旁边的小面朝下箭头 ?? 单击它然后取消选中类资源然后您就可以开始了