How to ignore certain files in git?

2019-01-02 16:23发布

I have a repository with a file Hello.java. When I compile it an additional Hello.class file is generated.

I created an entry for Hello.class in a .gitignore file. However the file still appears to be tracked.

I want to know how to make git ignore Hello.class.

标签: git gitignore
17条回答
不流泪的眼
2楼-- · 2019-01-02 16:44

You should write something like

*.class

into your .gitignore file.

查看更多
妖精总统
3楼-- · 2019-01-02 16:45

Add the following line to .gitignore:

/Hello.class

This will exclude Hello.class from git. If you have already committed it, run the following command:

git rm Hello.class

If you want to exclude all class files from git, add the following line to .gitignore:

*.class
查看更多
怪性笑人.
4楼-- · 2019-01-02 16:48

How to ignore new files

Globally

Add the path(s) to your file(s) which you would like to ignore to your .gitignore file (and commit them). These file entries will also apply to others checking out the repo.

Locally

Add the path(s) to your file(s) which you would like to ignore to your .git/info/exclude file. These file entries will only apply to your local working copy.

How to ignore changed files (temporarily)

In order to ignore changed files to being listed as modified, you can use the following git command:

git update-index --assume-unchanged <file>

To revert that ignorance use the following command:

git update-index --no-assume-unchanged <file>
查看更多
余生请多指教
5楼-- · 2019-01-02 16:48

By creating a .gitignore file. See here for details: Git Book - Ignoring files

Also check this one out: How do you make Git ignore files without using .gitignore?

查看更多
明月照影归
6楼-- · 2019-01-02 16:49

I had a similar issue with file "dump.rdb".
I tried adding this file in various ways to .gitignore file, but only one way worked.

Add your filename, at the end of .gitignore file

NOTE: Adding the file anywhere else didn't work.

For example, see: https://gitlab.com/gitlab-org/gitlab-ce/raw/b3ad3f202478dd88a3cfe4461703bc3df1019f90/.gitignore

查看更多
大哥的爱人
7楼-- · 2019-01-02 16:50

Create a .gitignore in the directory where .git is. You can list files in it separated by a newline. You also can use wildcards:

*.o
.*.swp
查看更多
登录 后发表回答