Part 3 - git:How to Fix Gitignore Not Working?
How to Fix Gitignore Not Working?
This is because Git can only ignore the untracked files.
In order to fix the .gitignore not working issue, it is necessary to have an overall understanding of gitignore. This issue often occurs when the .gitignore files can’t work in GitHub.
The file won’t be ignored once it is already added to the repository. Even if you have changed its name or rule in the .gitignore file, Git can’t ignore it.
Table of Contents
工作区(working tree): 本地编辑器
暂存区(index):git add操作后进入暂存区,可用git status查看 - 文件状态变为:Staged
本地仓库(repository):git commit 后进入本地仓库
Tracked: These files are previously either committed or staged in history.
Untracked: These files haven’t been staged or committed previously.
Ignored: They are the files that can be set by users to ignore completely.
step 1:add new file media/test.wav
test.wav in working tree - Untracked
git add . -> test.wav in index - Tracked (not Untracked) - Gitignore Not Working
git commit -> test.wav in repository(local) - Tracked (not Untracked) - Gitignore Not Working
git -m push -> -> test.wav in repository(github remote) - Tracked (not Untracked) - Gitignore Not Working
Quick Start
cd /data
sudo git rm -r --cached .
sudo git add .
sudo git commit -m 'update .gitignore'
sudo git push -u origin main
Step 1. Type the following command and hit Enter to execute it. This command will unstage and remove the path to your files from the Git index.
sudo git rm -r --cached .
Step 2. Execute the following command. It will re-add all your files back and only the correct files will be updated.
sudo git add .
Step 3. Execute the following command to commit all your files back into the Git index.
sudo git commit -m 'update .gitignore'
git commit -m ".gitignore is now working"
Step 4.
sudo git push -u origin main
Ignoring __pycache__ in Git
**/__pycache__
Test
use find command with -exec parameter and try to add each file separately instead of adding everything at once
find . -name '*' -exec git add {} \;
output
The following paths are ignored by one of your .gitignore files:
homeassistant/www/community
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"
https://github.com/arsaboo/homeassistant-config/blob/master/.gitignore
.gitignore
./homeassistant202405/media/*
./homeassistant202405/backups/*
./homeassistant202405/.storage/tmp*
**/__pycache__
./homeassistant202405/tts/*
./homeassistant202405/.gitignore.swp
./homeassistant202405/home-assistant.log
./homeassistant202405/home-assistant.log.*
./homeassistant202405/home-assistant.log.fault
./homeassistant202405/home-assistant_v2.db
./homeassistant202405/home-assistant_v2.db-shm
./homeassistant202405/home-assistant_v2.db-wal
# Logs
logs
*.log
# Python cache
__pycache__
*.pyc
# Other
*.uuid
*.conf
*.db
*.db-journal
*.log
*.noload
*.txt
*.sqlite
*.xml
*.backup
*.json
life360.sh
.ip_authenticated.yaml
ip_bans.yaml
.config_entries.json
*.google.token
.google.token
.ring_cache.pickle
.spotify-token-cache
.storage
abodepy_cache.pickle
camera_recording.py
home-assistant.env
home-assistant.*
known_devices.yaml
entity_registry.yaml
secrets.yaml
google_calendars.yaml
SERVICE_ACCOUNT.json
components
deps
tts
www/icons
www/floorplans
www/community
custom_components/hacs
downloads
icloud
dlib_faces
dlib_nofaces
dlib_known_faces
dlib_unknown_faces
.cloud
*.pickle
.pc-session
google*.deb
.homekit.state
https://github.com/arsaboo/homeassistant-config/blob/master/.gitignore
Useful links
https://blog.csdn.net/a529975125/article/details/115125614
https://blog.csdn.net/Q1761991696/article/details/123572766
https://www.partitionwizard.com/partitionmagic/gitignore-not-working.html
Comments
Comments are closed