Tag Archives: Git ignore rule does not work

Git ignore rule (.Gitignore configuration) does not Wrok [How to Fix]

The first method

.gitignore indicates the files under the ignored file directory. When git pushes, they will also appear in the pushed directory, or use git status to view the status. The files you want to ignore will still display the tracked status.

The reason is that in the GIT ignore directory, new files will be cached in GIT. If some files have been included in version management, even if the ignore path has been declared in .Gitignore, it will not work,

At this time, we should delete the local cache first, and then commit git, so that there will be no ignored files.

Solution: git clears the local cache (changes to untrack state), and then commits:

[root@kevin ~]# git rm -r --cached .
[root@kevin ~]# git add .
[root@kevin ~]# git commit -m 'update .gitignore'
[root@kevin ~]# git push -u origin master

Special attention should be paid to:

1) .gitignore can only ignore files that have not been tracked. If some files have been included in version management, modifying. Gitignore is invalid.

2) If you want .Gitignore to work, you must make sure that these files are not in the staging area .Gitignore only ignores files that are not staged (cached),

For files that have been staged, the ignore file must be removed from the staged file before it can be ignored.

To remove a file from the staging area, use the command

use "git restore <file>..." to discard changes in working directory

Second method: (recommended)

Manually set in the warehouse under each clone. Do not check the changes of specific files.

[root@kevin ~]# git update-index --assume-unchanged PATH         //Enter the files to be ignored in the PATH