Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

git - 如何忽略Git中的某些文件(How to ignore certain files in Git)

I have a repository with a file, Hello.java .

(我有一个带有文件Hello.java的存储库。)

When I compile it, an additional Hello.class file is generated.

(当我编译它时,会生成一个附加的Hello.class文件。)

I created an entry for Hello.class in a .gitignore file.

(我在.gitignore文件中为Hello.class创建了一个条目。)

However, the file still appears to be tracked.

(但是,该文件似乎仍被跟踪。)

How can I make Git ignore Hello.class ?

(如何使Git忽略Hello.class ?)

  ask by Kohan95 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is that .gitignore ignores just files that weren't tracked before (by git add ).

(问题是.gitignore只会忽略之前未跟踪的文件(通过git add )。)

Run git reset name_of_file to unstage the file and keep it.

(运行git reset name_of_file取消git reset name_of_file文件并保留它。)

In case you want to also remove the given file from the repository (after pushing), use git rm --cached name_of_file .

(如果您还想从存储库中删除给定的文件(在推送之后),请使用git rm --cached name_of_file 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...