.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条回答
Fickle 薄情
2楼-- · 2020-02-17 09:53

Your file must still be tracked, you can see by doing git status that will show you that your file is modified even if it's in .gitignore
You need to do this:

git update-index --assume-unchanged [path_to_file]
查看更多
小情绪 Triste *
3楼-- · 2020-02-17 09:53

I'm using git version 1.7.12.3 on MacOSX and the first line of .gitignore is also not taken into account. Just add a comment as first line.

查看更多
Ridiculous、
4楼-- · 2020-02-17 09:57

A trick I faced on windows is that using echo (as per Jakub Narębski answer) you have to be careful with spaces.

As you can see below any space before the redirection operator does have an effect on the actual ignore.

C:\test>dir /B
TOBEIGNORED

C:\test>echo TOBEIGNORED > .gitignore
C:\test>git status
[...]
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
#       TOBEIGNORED
C:\test>echo TOBEIGNORED> .gitignore
C:\test>git status
[...]
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
nothing added to commit but untracked files present (use "git add" to track)
查看更多
登录 后发表回答