Git忽略Eclipse中的特定文件 [英] Git ignore a specific file in Eclipse
问题描述
我猜这个问题已经被问了很多次(我已经看过关于这个主题的SO的几个问题),但是我仍然有一个问题要忽略我的Git文件。
I guess this kind of question has been asked many times (and I've seen several questions on SO dealing with this subject) but I still have a problem to ignore a file in my Git.
<我的项目的强>结构如下所示:
myProject/
.gitignore
src/test/java/packageName/
Main.java
我想忽略 Main.java
(每个用户的文件不同)。
I would like to ignore Main.java
(the file is different between each user).
.gitignore 文件
.settings
.project
.classpath
target/
test-output/
node_modules/**
.orig
我尝试过:
I've tried:
-
添加
src / test / java / packageName / Main.java
到我的.gitignore
。
在 src / test / java / packageName /
中创建一个 .gitignore
文件,其中包含 Main.java
。
Creating a .gitignore
file in src/test/java/packageName/
that just contains Main.java
.
这两种解决方案都没有影响:重新启动Eclipse后,Git Staging视图中的 Main.java
Both solutions have no effect: I still see Main.java
in the Git Staging view after restarting Eclipse.
我猜解决方案很简单,但我坚持了好几个小时,希望你能帮助我。
I guess the solution is simple, but I'm stuck on it for several hours, and I hope you can help me.
谢谢! : - )
更新
所有Git用户具有 Main.java
,但该类别与一个人不同(用户名在类中硬编码)。
All Git users have Main.java
, but the class is different from one person to another (user name hardcoded in the class).
我希望这个类可以出现在HEAD分支上(以便新开发人员可以恢复它),但是每个开发人员都可以拥有本地版本(在Git Staging中不可见)
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).
推荐答案
您的问题可能是Main.java已经在您的索引中。
解决方案
Your problem is probably that Main.java is already in your index. The solution
首先让它消失
git rm src/test/java/packageName/Main.java
然后将其添加到您的gitignore
then add it to your gitignore
echo "src/test/java/packageName/Main.java" >> .gitignore
现在提交这些更改
git add .gitignore
git commit -m "please ignore me!"
它应该工作: - )
现在,您可以重新创建Main.java,它不应再出现在 git status
中。
You can now recreate your Main.java and it should no longer appear in git status
.
这篇关于Git忽略Eclipse中的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!