Git ignores files.gitignore
In a project, not all files need to be saved in the version library, such as the "target" directory and files under the directory can be ignored. Create a special .gitignore file in the root directory of the Git workspace, and then fill in the file name to be ignored, and Git will automatically ignore these files or directories.
Basic usage of gitignore
# .Gitignore configuration file common tips [Reference:/docs/gitignore]
# 1. The blank line does not match any file, so it can be used as a readability separator, and the spaces at both ends will be ignored.
# 2. Using the beginning of [#] will comment out the entire line so that it does not perform matching operations. If you need to match the beginning of #, you can use the escape character [\].
# 3.1 The matching pattern ends with [/], indicating that you want to match a directory and its subfiles. (For example, [foo/] will match the foo directory and its path below.)
# 3.2 The matching pattern does not contain [/], and the file will be matched globally.
# 4. Wildcard
# [*]: Matching anything other than [/] means [*] cannot cross directories.
# [?]: Match any character except [/] and [[] and []].
# [**]: Match all contents, or match contents in any directory.
# Example:
# 1.[**/foo/bar] It will match all bars directly in the foo directory, no matter where foo is.
# 2.[foo/**] means that it matches all files and directories in the foo directory.
# 3.[a/**/b] can match a/b, a/c/b, a/c/d/b, that is, the [**] here can represent 0 or more.
# !!! It should be noted that except for the usage of the above example, the remaining [**] are all invalid..
# 5. The prefix [!] can be used to indicate that certain files are not ignored. For example, [!a] can be used to ensure that file a will not be ignored. In fact, it has already stated that it has ignored its parent directory. This mode has a higher priority than the normal ignorance mode.
Git three ways to ignore submitted files
Define .gitignore files in Git project
This way, by defining the .gitignore file in a folder of the project and defining corresponding ignorance rules in the file, to manage the Git commit behavior of files in the current folder.
The .gitignore file can be submitted to a public repository, which allows all developers under the project to share a set of defined ignore rules.
In the .gitingore file, follow the corresponding syntax and specify an ignorance rule on each line. like:
*.log *.temp /vendor2\
Specify exclusion files in settings of Git project
This method simply specifies the behavior of the project temporarily, requires editing the .git/info/exclude file under the current project, and then writing the file that needs to be ignored to it.
It should be noted that the root directory of the ignored file specified in this way is the project root directory.
Define Git global .gitignore file
In addition to defining .gitignore files in your project, you can also set up a global git .gitignore file to manage the behavior of all Git projects. This method is not shared among different project developers, and is a Git application-level behavior above the project.
This method also requires the creation of the corresponding .gitignore file, which can be placed anywhere. Then configure it using the following command
Git: git config --global \~/.gitignore
Ignore rules in .gitignore files
If the space does not match any file, it can be used as a delimiter and can be escaped by backslashes.
# Start: Identify comments, you can use backslashes to escape
! Starting: The flag is negative, the file will be included again, and if the parent directory of the file is excluded, the ! will not be included again. You can escape with backslashes
/End: Only matches the folder and the contents under the folder path, but does not match the file
/ Beginning: Match the file
If a pattern does not contain slashes, it matches the contents relative to the current .gitignore file path, and if the pattern is not in the .gitignore file, relative to the project root directory if the pattern is not in the .gitignore file
** Match multi-level directories, can be started, middle, and end
?
Universal matching single character
[]
Universal matching single character list
Commonly used matching examples:
bin/ :Ignore the current pathbinFolders,该Folders下的所有内容都会被neglect,Don't ignore it bin document /bin :Ignore the root directorybindocument /*.c: ignore , not ignore build/ debug/*.obj: ignore debug/, not ignore debug/common/ and tools/debug/ **/foo : neglect/foo, a/foo, a/b/foowait a/**/b : neglecta/b, a/x/b, a/x/y/bwait !/bin/ : Don't ignore it bin In the directory document \*.log : neglect所有 .log document : neglect当前路径的 document
Java ignores files
# compiled class files, ignore all files ending with [.class]*.class # Log files, ignore all files ending with [.log].*.log # BlueJ file, ignore all files ending with [.ctxt].*.ctxt # Mobile Tools for Java (J2ME), ignore the [./] directory and its subfiles../ # Package files and ignore all files ending in [.jar] or [.war] or [.nar] or [.ear] or [.zip] or [.] or [rar].*.jar *.war *.nar *.ear *.zip *. *.rar
IDE environment ignores files
.idea/* .idea/ .idea/ .idea/ *.iml
maven ignores files
target/ .mvn/ # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) !/.mvn/wrapper/
Other environment ignores files
*.sw? .#* *# *~ .classpath .project .settings/ bin build target *.sublime-* /scratch .gradle Guardfile *.iml .idea
.gitignore rules do not take effect
.gitignore can only ignore files that were not tracked. If some files have been included in version management, modifying .gitignore is invalid.
The solution is to delete the local cache first (change it to an untracked state) **, and then submit:
git rm -r cached . git add . git commit -m 'update .gitignore'
Summarize
This is the article about Git ignore files.gitignore operation methods. For more related Git ignore files.gitignore content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!