If you want to ignore a file in git and prevent it from being submitted to the version library, you can use the method of modifying the. gitignore file. Each row of this file stores a matching rule, for example:
# This is a comment-it will be ignored by git
*. A # ignore all files ending with.
! Lib. A # Except Lib.
/Todo # ignore the todo file in the root directory of the project, excluding subdir/todo
Build/# ignore all files in the build/directory
DOC/*. txt # will ignore DOC/notes.txt, but does not include DOC/Server/arch.txt
In this way, all. PyC files will not be added to the version library.
In addition, git provides a global. gitignore, which you can create in your user directory ~ /. Gitignoreglobal file, with the same rules to determine which files do not require version control.
You need to execute git config -- global core. excludesfile ~ /. Gitignoreglobal to make it take effect.
Other filtering Conditions
*? : Represents any character
**: Represents any number of characters
*{! AB}: it must not be of this type.
* {AB, BB, CX}: indicates any type of AB, BB, and Cx.
* [ABC]: represents any character in A, B, and C.
* [^ ABC]: indicates that it must not be A, B, or C.
Because git does not add an empty directory, the following method will prevent TMP from having tmp/* // ignore all files in the TMP folder.
Modify the method and add a. gitignore under TMP. The content is
*
!. Gitignore
Another case is that the request has been committed and adding gitignore is invalid. Therefore, you need to delete the cache.
Git Rm-r -- cached ignore_file
Note:. gitignore can only ignore files that have not been tracked. If some files have been included in version management, modifying. gitignore is invalid.
The correct method is to manually set in each cloned warehouse not to check the changes to specific files.
Git Update-index -- assume-unchanged path: Enter the file to be ignored in path.
In addition, git provides another exclude method to do the same thing. The difference is that the. gitignore file itself will be submitted to the version library. It is used to save public files to be excluded. The. Git/INFO/exclude settings here are the files you need to exclude locally. It will not affect others. It will not be submitted to the version library.
. Gitignore also has an interesting small feature. An empty. gitignore file can be considered as a placeholder. This is useful when you need to create an empty log directory for the project. You can create a log directory and place an empty. gitignore file in it. In this way, when you clone this repo, git will automatically create an empty log directory.
Git usage-set the project to ignore files