1. Configuration gitconfig
Git’s config file can be configured to define and save your preferences. Git’s config file has multiple different scopes, and the ones with higher priority will overwrite the ones with lower priority:
1.1 Three scopes
The config path | scope | Configuration commands | priority |
---|---|---|---|
project /.git/config |
project project |
Git config (–local) | high |
~/.gitconfig | The current user | git config –global | In the |
/etc/gitconfig | All Users of this machine | git config –system | low |
1.2 Configuration Operations
- View the configuration document:
git help config
- Viewing existing Configurations
The command | The results of |
---|---|
git config -l | Displays all levels of configuration in descending order of priority Permutation), that is, the last of multiple repetitions takes effect |
git config –local -l | Displays the configuration of this item |
git config –global -l | Displays the configuration of the current user |
git config –system -l | Displays the configuration of all users on the host |
git config —scope key | Displays the value of the specified key for the specified scope, For example, git config –global user.name |
- Configure the config
Configuration mode | operation |
---|---|
The command configuration | Git config –global user.name “kivi” |
Edit config file | For example, vim ~/.gitconfig |
1.3 Configuration Examples
To use Git correctly, simply configure it as follows:
git config --global user.name "kivi"
git config --global user.email [email protected]
Copy the code
2. Configure the ignore file
Git can configure ignore files to ignore specified files in a workspace, for example, Java projects can configure ignore files to prevent class files from being uploaded to git repositories.
2.1 Two Configuration files
- Git ignores two files:.gitignoreandexludeGit ignores both files based on their contents.
- Belonging to the workspace,.gitignore is a file of the project that is versioned by Git (stored as blob objects in the.git/objects/ directory like other files). Ignore files suitable for configuration project exposure, visible to other developers
- Git /info/exclude file is located in. Git /info/exclude. It is not a project and is not controlled by Git version management. Suitable for configuring local ignore files that are not visible to other developers
2.2 Grammar Rules
Git help ignore to view detailed rules
-
# Comment the initial behavior line
-
Absolute path and relative path
- Absolute path: to
/
Start path, for example:/bin/
Only files under the bin file in the root directory are ignored. - Relative path: No
/
Start path, for example:bin/
Ignore files in the bin folder at any level
- Absolute path: to
-
Ignore files or directories?
- FolderA /name: Ignores folderA
name
Files and folders. - FolderA /name/ : Ignores folderA
name
Folder.
- FolderA /name: Ignores folderA
-
Special characters:! ,? , *, ** and []
!
: excluding?
: matches any character.
】*
: Matches any number of characters (It behaves differently on Linux and WindowsLinux equivalent**
, Windows is different.)**
: matches any level of directory. *
】[]
: matches a character group [equivalent to regex][]
】
2.3 configuration gitignore
vim .gitignore
# This is a line comment
.[oa] # Ignore files or folders that end in. O or. A
.html # ignore files or folders that end in.html! foo.html# except foo.html
/bin/*.class # ignore files ending in. Class under /bin/, excluding /foo/bin/.class
lib/ # ignore all files in lib
target/*.jar # ignore.jar files under target, excluding target/foo/foo.jar
doc/**/*.txt # ignore all.txt files under doc
Copy the code
2.4 configuration exclude
Vim. git/info/exclude, see. Gitignore configuration.
reference
- Customize Git – Configure Git