开发者

.gitignore not working: files that should be ignored still get committed

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.


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


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]


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


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


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.


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)


Probably your exclude file mask is inacurate.


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.


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.


I lastly did echo node_modules >> .gitignore, and it wasn't working.

The windows terminal saves the file in UCS-2 LE BOM and git doesn't accept that.

It latter worked when I opened the file with Notepad and saved it with UTF-8 encoding

.gitignore not working: files that should be ignored still get committed

It Worked fine then.

I think they need to fix this since echo "filetoignore" >> .gitignore actually seems a handy thing to do

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜