Why is .gitignore not ignoring my files?

时光总嘲笑我的痴心妄想 提交于 2019-12-03 02:11:47

问题


See the image below. My .gitignore file should be ignoring all files in src/dist, but isn't.


回答1:


.gitignore only ignores files that are not part of the repository yet. If you already git added some files, their changes will still be tracked. To remove those files from your repository (but not from your file system) use git rm --cached on them.




回答2:


The .gitignore file ensures that files not tracked by Git remain untracked.

Just adding folders/files to a .gitignore file will not untrack them -- they will remain tracked by Git.

To untrack files, it is necessary to remove from the repository the tracked files listed in .gitignore file. Then re-add them and commit your changes.

The easiest, most thorough way to do this is to remove and cache all files in the repository, then add them all back. All folders/files listed in .gitignore file will not be tracked. From the top folder in the repository run the following commands:

git rm -r --cached . git add .

Then commit your changes:

git commit -m "Untrack files in .gitignore"

Please note that any previous commits with the unwanted files will remain in the commit history. When pushing to GitHub be aware of a commit history that might contain .env or client_secret.json files.

Best practice is to create a .gitignore file and populate it with the folders/files you do not want tracked when starting a project. However, often it is necessary to add to the .gitignore file after realising that unwanted files are being tracked and stored.




回答3:


gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed and the past and their are now tracked by git.

To ignore them, you first need to delete them, git rm them, commit and then ignore them.




回答4:


Look at this : .gitignore is not working And particularly the remark from ADTC:

Make sure your .gitignore file uses ANSI or UTF-8 encoding. If it uses something else like Unicode BOM, it's possible that Git can't read the file. – ADTC Dec 14 '17 at 12:39



来源:https://stackoverflow.com/questions/45400361/why-is-gitignore-not-ignoring-my-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!