1.gitignore file
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 # ignores all files ending with. A
!LIB.A # but except LIB.A
/todo # simply ignores the TODO file under the project root directory, excluding Subdir/todo
build/# ignores all files in 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.
2.gitignoreglobal Global Ignore File
In addition, GIT provides a global. Gitignore, you can create a ~/.gitignoreglobal file in your user directory, using the same rules to delimit which files are not required for versioning.
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
Because Git does not join an empty directory, the following practices cause TMP to not exist tmp/*//Ignore TMP folder all files
Change the method, under TMP also add a. Gitignore, the content is
*
!. Gitignore
In another case, it is already committed, and then adding Gitignore is invalid, so you need to delete the 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.
It is a good practice to manually set up in each clone down warehouse to not check for specific file changes.
Git update-index--assume-unchanged path enters the file to be ignored at path.
In addition, GIT offers another way to do the same thing, exclude. 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.
3.git rm-r--cached Display of Divinity
Sometimes, however, Gitignore is not fully considered, and it is not possible to simply add the ignore in the. Gitignore when it is found that a file that should not be submitted has been submitted. This time needs to be executed:
git rm-r--cached filename
Remove the files that you have already managed, and then submit them.
git rm-r--cached get rid of files already hosted on Git