.gitignore not working: files that should be ignor

2020-02-17 09:06发布

I'm trying to create a new git repository from existing folder. I've created a .gitignore file in the root of the folder. But if I say

git add *
git commit
git push

files that should be ignored still get committed to the remote repository. I'm on Windows. Also I've bought a license for SmartGIT. It also seems to ignore .gitignore. I have to manually select which new files to commit.

标签: git
9条回答
在下西门庆
2楼-- · 2020-02-17 09:39

Comment line as the first line of the file is critical! I spent considerable time trying to exclude files only to find that GIT was ignoring the first line in the ignore file.

查看更多
Luminary・发光体
3楼-- · 2020-02-17 09:40

I've had issues with .gitignore also. I checked out the linked answers listed about, which fixed half the issue.

What really got gitignore working full for me was adding a comment on the first line of the file. Git wasn't parsing the exclude situated on the first line.

Cheers

查看更多
Fickle 薄情
4楼-- · 2020-02-17 09:41

Are your files already tracked? .gitignore only silences comments about untracked files, but won't stop a tracked file from being tracked.

查看更多
贼婆χ
5楼-- · 2020-02-17 09:42

Try "git add ." instead.

Also, it works for me (on Linux):

$ git init
$ echo foo > .gitignore
$ echo foo > foo
$ echo bar > bar
$ git add -v *
The following paths are ignored by one of your .gitignore files:
foo
Use -f if you really want to add them.
fatal: no files added
查看更多
▲ chillily
6楼-- · 2020-02-17 09:42

Probably your exclude file mask is inacurate.

查看更多
\"骚年 ilove
7楼-- · 2020-02-17 09:48

You could have created a UTF-8 encoded text file. Try saving it as ANSI encoded. In git bash, you can verify by using vi -b.

查看更多
登录 后发表回答