In Git, if you want to ignore a file and not commit the file to the repository, you can use the method that modifies the. gitignore file. Each row of this file holds a matching rule for example:
# This is a comment – will be ignored by Git
*.a # Ignore All. A End of File
!lib.a # except LIB.A
/todo # Just ignore the TODO file under the project root, not including Subdir/todo
build/ # ignores all files under the build/directory
Doc/*.txt # ignores Doc/notes.txt but does not include Doc/server/arch.txt
This sets up all future. pyc files that are not added to the repository.
In addition, GIT provides a global. Gitignore , you can create a ~/.gitignoreglobal file under your user directory, using the same rules to delimit which files are not required for version control.
You need to execute git config--global core.excludesfile ~/.gitignoreglobal to make it effective.
Some of the other filtering conditions
* ? : Represents any one character
* *: Represents any number of characters
* {!AB}: Must not be of this type
* {AB,BB,CX}: Represents any type of AB,BB,CX
* [ABC]: represents any one character in A,b,c
* [^ABC]: represents must not be any one character in A,b,c
tmp/* //Ignore TMP folder all files
to change the method, under TMP also add a. Gitignore, the content is
*
!. Gitignore
Another case is that it is already committed, and then adding Gitignore is not valid, so you need to delete the next cache
git rm-r--cached ignore_file
Note:. Gitignore can only ignore files that were not previously track, and if some files have already been included in version management, modify the. Gitignore is not valid.
the correct approach is to manually set up in each clone down warehouse to not check for specific file changes.
git update-index--assume-unchanged path Enter the file you want to ignore at PATH.
In addition git also provides another way to exclude to do the same thing, unlike the. Gitignore the file itself is submitted to the repository. It is used to save the public files that need to be excluded. The. Git/info/exclude here is the file you need to exclude locally. He will not affect other people. Will not be submitted to the repository.
. Gitignore also has an interesting little feature, an empty. gitignore file can be considered as a placeholder. This becomes useful when you need to create an empty log directory for your project. You can create a log directory to place an empty. gitignore file inside. So when you clone this repo git will automatically create an empty log directory.
---------------------------------------------------------------------------------------------------------------
Local permanent neglect, the effect of gitignore, just not suitable for writing to Gitignore, you can build a local gitignore, and then git config--global core.excludesfile file absolute path, You can also add files that are local to ignore directly to the. Git/info/exclude.
$ git update-index--assume-unchanged/path/to/file #忽略跟踪
$ git update-index--no-assume-unchanged/path/to/file #恢复跟踪
git update-index--assume-unchanged (ignoring changes to tracked files)