Why doesn't .gitignore ignore my files?

See image below. My .gitignore file should ignore all files in src / dist, but that is not the case.

enter image description here

+18
source share
4 answers

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

+41
source

gitignore ignores only unsaved files. Your files are marked as modified - this means that they were committed, and the past, and now they are tracked by git.

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

+5
source

The .gitignore file ensures that files not tracked by Git are left without a trace.

Just adding folders / files to the .gitignore file will not eliminate them - they will be tracked by Git.

To track files, you must remove the tracked files listed in the.gitignore file from the repository. Then add them and make changes.

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

git rm -r --cached. git add.

Then make your changes:

git commit -m "Untrack files in.gitignore"

Note that any previous commits with unwanted files remain in the commit history. When you click on GitHub, you should know the commit history, which may contain .env or client_secret.json .

The best practice is to create a .gitignore file and populate it with folders / files that you do not want to keep track of when you start the project. However, it is often necessary to add a .gitignore to the file after you know that unwanted files are tracked and saved.

0
source

Look at this: .gitignore is not working. And, in particular, a comment from ADTC:

Make sure your .gitignore file uses ANSI or UTF-8 encoding. If it uses something like Unicode BOM, maybe Git cannot read the file. - ADTC Dec 14 '17 at 12:39

0
source

Source: https://habr.com/ru/post/1270365/


All Articles