git rm-r--cached get rid of files already hosted on Git

Source: Internet
Author: User
Tags tmp folder

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.