- Git Version Control Cookbook
- Aske Olsson Rasmus Voss
- 563字
- 2021-12-08 12:33:49
Configuration targets
In this section, we will look at the different layers that can be configured. The layers are:
SYSTEM
: This layer is system-wide and found in/etc/gitconfig
GLOBAL
: This layer is global for the user and found in~/.gitconfig
LOCAL
: This layer is local to the current repository and found in.git/config
Getting ready
We will use the jgit
repository for this example; clone it or use the clone you already have from Chapter 1, Navigating Git, as shown in the following command:
$ git clone https://git.eclipse.org/r/jgit/jgit $ cd jgit
How to do it...
In the previous example, we saw how we could use the command git config --list
to list configuration entries. This list is actually made from three different levels of configuration that Git offers: system-wide configuration, SYSTEM
; global configuration for the user, GLOBAL
; and local repository configuration, LOCAL
.
For each of these configuration layers, we can query the existing configuration. On a Windows box with a default installation of the Git extensions, the different configuration layers will look approximately like the following:
$ git config --list --system core.symlinks=false core.autocrlf=true color.diff=auto color.status=auto color.branch=auto color.interactive=true pack.packsizelimit=2g help.format=html http.sslcainfo=/bin/curl-ca-bundle.crt sendemail.smtpserver=/bin/msmtp.exe diff.astextplain.textconv=astextplain rebase.autosquash=true $ git config --list --global merge.tool=kdiff3 mergetool.kdiff3.path=C:/Program Files (x86)/KDiff3/kdiff3.exe diff.guitool=kdiff3 difftool.kdiff3.path=C:/Program Files (x86)/KDiff3/kdiff3.exe core.editor="C:/Program Files (x86)/GitExtensions/GitExtensions.exe" fileeditor core.autocrlf=true credential.helper=!\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winst ore.exe\" user.name=Aske Olsson user.email=aske.olsson@switch-gears.dk $ git config --list --local core.repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true core.symlinks=false core.ignorecase=true core.hidedotfiles=dotGitOnly remote.origin.url=https://git.eclipse.org/r/jgit/jgit remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master
We can also query a single key and limit the scope to one of the three layers, by using the following command:
$ git config --global user.email aske.olsson@switch-gears.dk
We can set the e-mail address of the user to a different one for the current repository:
$ git config --local user.email aske@switch-gears.dk
Now, listing the GLOBAL
layer user.email
will return aske.olsson@switch-gears.dk
, listing LOCAL
gives aske@switch-gears.dk
, and listing user.email
without specifying the layer gives the effective value that is used in the operations on this repository, in this case, the LOCAL
value aske@switch-gears.dk
. The effective value is the value, which takes precedence when needed. When two or more values are specified for the same key, but on different layers, the lowest layer takes precedence. When a configuration value is needed, Git will first look in the LOCAL
configuration. If not found here, the GLOBAL
configuration is queried. If it is not found in the GLOBAL
configuration, the SYSTEM
configuration is used. If none of this works, the default value in Git is used.
In the previous example, user.email
is specified in both the GLOBAL
and LOCAL
layers. Hence, the LOCAL
layer will be used.
How it works...
Querying the three layers of configuration simply returns the content of the configuration files: /etc/gitconfig
for system-wide configuration, ~/.gitconfig
for user-specific configuration, and .git/config
for repository-specific configuration. When not specifying the configuration layer, the returned value will be the effective value.
There's more...
Instead of setting all the configuration values on the command line by the key value, it is possible to set them by just editing the configuration file directly. Open the configuration file in your favorite editor and set the configuration you need, or use the built-in git config -e
repository to edit the configuration directly in the Git-configured editor. You can set the editor to the editor of your choice either by changing the $EDITOR
environment variable or with the core.editor
configuration target, for example:
$ git config --global core.editor vim
- 企業級Java EE架構設計精深實踐
- FreeSWITCH 1.8
- Building a Game with Unity and Blender
- Learning Neo4j 3.x(Second Edition)
- Apache Karaf Cookbook
- Python機器學習實戰
- FFmpeg入門詳解:音視頻原理及應用
- C語言程序設計
- Procedural Content Generation for C++ Game Development
- JavaScript應用開發實踐指南
- 小程序從0到1:微信全棧工程師一本通
- 測試架構師修煉之道:從測試工程師到測試架構師
- Android系統下Java編程詳解
- Monitoring Docker
- IBM RUP參考與認證指南