git提交屏蔽某java类,Git忽略Eclipse中的特定文件

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.

The structure of my project looks like this:

myProject/

.gitignore

src/test/java/packageName/

Main.java

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

.gitignore file

.settings

.project

.classpath

target/

test-output/

node_modules/**

.orig

I've tried:

Adding src/test/java/packageName/Main.java to my .gitignore.

Creating a .gitignore file in src/test/java/packageName/ that just contains 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.

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).

解决方案

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

The solution

First make it disappear

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

then add it to your 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值