1, Foreword
- Git always runs in a bash shell and uses some shell environment variables to determine how it runs.
- Sometimes it's useful to know what they are and how they make Git run the way you want.
2, Global behavior
- Like normal programs, Git's normal behavior depends on environment variables.
- GIT_EXEC_PATH determines where Git can find its subroutines (such as Git commit, Git diff, etc.), and Git -- exec path can be used to view the current settings.
- You usually don't consider modifying the variable HOME (too many other things rely on it). This is where Git looks up the global configuration file. If you want a real portable Git with global configuration, you can override the HOME setting in the shell configuration of the portable Git.
- PREFIX is similar. Except for system level configuration, Git looks for this file in $PREFIX/etc/gitconfig.
- If Git is set_ CONFIG_ Nosystem, disable the system level configuration file, which is very useful when the system configuration affects the command without permission to modify.
- GIT_PAGER controls the program that displays multi page output on the command line. If this is not set, PAGER will be used.
- GIT_EDITOR when the user needs to edit some text (such as submitting information), Git will start the EDITOR. If it is not set, EDITOR will be used.
3, Version library location
- Git uses several variables to determine how it interacts with the current version library.
- GIT_DIR is the location of the. Git directory. If this is not set, Git will look up the. Git directory layer by layer according to the directory tree until it reaches ~ or /.
- GIT_CEILING_DIRECTORIES controls the behavior of finding. Git directories. If you access directories that load slowly (such as those on tape drives or accessed through a network connection), you may want git to stop trying earlier, especially when Git is called during shell construction.
- GIT_WORK_TREE is the root path of the working directory of the non empty version library. If -- git dir or Git is specified_ Dir, but -- work tree, GIT are not specified_ WORK_ Tree or core.worktree, the current working directory will be regarded as the top-level directory of the working tree.
- GIT_INDEX_FILE is the path to the index file (only non empty version libraries have it).
- GIT_OBJECT_DIRECTORY is used to specify the location of the. git/objects directory.
- GIT_ALTERNATE_OBJECT_DIRECTORIES is a colon separated list (format similar to / dir/one:/dir/two:...) used to tell Git where to find the missing Git_ OBJECT_ For objects in the directory, if many projects have large files with the same content, this can be used to avoid storing too many backups.
4, Path rule
- The so-called "pathspec" refers to how to specify the path in Git, including the use of wildcards. They will be used in the. gitignore file and the command line (git add *.c).
- GIT_GLOB_PATHSPECS and GIT_NOGLOB_PATHSPECS controls the default behavior of wildcards in path rules. If GIT_GLOB_PATHSPECS is set to 1, and wildcards appear as wildcards (this is the default setting); If GIT_NOGLOB_PATHSPECS is set to 1. The wildcard only matches the literal meaning, which means that. c will only match the file with the file name ". c", not the file ending in. c. This configuration can be overwritten with: (glob) or: (literal) in each path specification, such as: (glob)*.c.
- GIT_LITERAL_PATHSPECS disables the above two behaviors; Wildcards cannot be used, nor can prefix overrides.
- GIT_ICASE_PATHSPECS lets all path specifications ignore case.
5, Submit
- Git commit tree usually completes the creation of GIT commit objects at last. Git commit tree uses these environment variables as the main information source, and only when these values do not exist will it fall back to the preset values.
- GIT_AUTHOR_NAME is the readable name of the "author" field.
- GIT_AUTHOR_EMAIL is the message for the "author" field.
- GIT_AUTHOR_DATE is the timestamp of the "author" field.
- GIT_COMMITTER_NAME is the readable name of the "committer" field.
- GIT_COMMITTER_EMAIL is the message in the "committer" field.
- GIT_COMMITTER_DATE is the timestamp of the "committer" field.
- If user.email is not configured, the EMAIL address specified by EMAIL will be used. If this is not set, Git will continue to fallback and use the system user and host name.
6, Network
- Git uses curl library to complete network operations through HTTP, so GIT_CURL_VERBOSE tells git to display all messages generated by that library, which is similar to executing curl -v on the command line.
- GIT_SSL_NO_VERIFY tells Git not to verify the SSL certificate, which is necessary sometimes. For example, a self signed certificate is used to provide Git services through HTTPS, or a Git server is being built and a complete certificate has not been installed.
- If git operates at a network speed lower than GIT_HTTP_LOW_SPEED_LIMIT bytes / sec and lasts Git_ HTTP_ LOW_ SPEED_ Git will terminate the operation when the time is more than seconds, and these values will override the configured values of http.lowSpeedLimit and http.lowSpeedTime.
- GIT_HTTP_USER_AGENT sets the user agent that Git uses when communicating over HTTP. The default value is similar to git/2.0.0.
7, Comparison and consolidation
- GIT_DIFF_OPTS has a wrong name. Valid values only support - u or -- unified =, which is used to control the number of content lines displayed in the git diff command.
- GIT_EXTERNAL_DIFF is used to override the value of diff.external configuration. If this value is set, Git will call the program when git diff is executed.
- GIT_DIFF_PATH_COUNTER and GIT_DIFF_PATH_TOTAL for Git_ EXTERNAL_ The program specified by diff or diff.external is useful. The former indicates which is compared in a series of files (starting from 1), and the latter indicates the total number of files in each batch.
- GIT_ MERGE_ Version controls the output of recursive merge strategy. The default value is 2. The allowed values are:
-
- 0 does not output anything except an error message;
-
- 1. Display only conflicts;
-
- 2 also display file changes;
-
- 3. Display the skipped file because there is no change;
-
- 4. Display all paths of processing;
-
- 5 display detailed debugging information.
8, Debug
- Want to really know what Git is doing? Git has built-in quite complete tracking information. All we need to do is open them. The available values of these variables are as follows:
-
- "true", "1" or "2" -- the trace category is written to the standard error output;
-
- Absolute path starting with / -- trace output will be written to that file.
- GIT_TRACE controls routine tracing, which is not applicable to special cases. Its scope of tracing includes alias expansion and delegation of other subroutines:
$ GIT_TRACE=true git lga
20:12:49.877982 git.c:554 trace: exec: 'git-lga'
20:12:49.878369 run-command.c:341 trace: run_command: 'git-lga'
20:12:49.879529 git.c:282 trace: alias expansion: lga => 'log' '--graph' '--pretty=oneline' '--abbrev-commit' '--decorate' '--all'
20:12:49.879885 git.c:349 trace: built-in: git 'log' '--graph' '--pretty=oneline' '--abbrev-commit' '--decorate' '--all'
20:12:49.899217 run-command.c:341 trace: run_command: 'less'
20:12:49.899675 run-command.c:192 trace: exec: 'less'
- GIT_TRACE_PACK_ACCESS controls the tracking information of accessing the packaged file. The first field is the accessed packaged file, and the second is the offset of the file:
$ GIT_TRACE_PACK_ACCESS=true git status
20:10:12.081397 sha1_file.c:2088 .git/objects/pack/pack-c3fa...291e.pack 12
20:10:12.081886 sha1_file.c:2088 .git/objects/pack/pack-c3fa...291e.pack 34662
20:10:12.082115 sha1_file.c:2088 .git/objects/pack/pack-c3fa...291e.pack 35175
# [...]
20:10:12.087398 sha1_file.c:2088 .git/objects/pack/pack-e80e...e3d2.pack 56914983
20:10:12.087419 sha1_file.c:2088 .git/objects/pack/pack-e80e...e3d2.pack 14303666
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
- GIT_TRACE_PACKET opens the tracking information at the network operation package level:
$ GIT_TRACE_PACKET=true git ls-remote origin
20:15:14.867043 pkt-line.c:46 packet: git< # service=git-upload-pack
20:15:14.867071 pkt-line.c:46 packet: git< 0000
20:15:14.867079 pkt-line.c:46 packet: git< 97b8860c071898d9e162678ea1035a8ced2f8b1f HEAD\0multi_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2.0.4
20:15:14.867088 pkt-line.c:46 packet: git< 0f20ae29889d61f2e93ae00fd34f1cdb53285702 refs/heads/ab/add-interactive-show-diff-func-name
20:15:14.867094 pkt-line.c:46 packet: git< 36dc827bc9d17f80ed4f326de21247a5d1341fbc refs/heads/ah/doc-gitk-config
# [...]
- GIT_TRACE_PERFORMANCE controls the log printing of performance data. The output shows the time spent on each git command call:
$ GIT_TRACE_PERFORMANCE=true git gc
20:18:19.499676 trace.c:414 performance: 0.374835000 s: git command: 'git' 'pack-refs' '--all' '--prune'
20:18:19.845585 trace.c:414 performance: 0.343020000 s: git command: 'git' 'reflog' 'expire' '--all'
Counting objects: 170994, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (43413/43413), done.
Writing objects: 100% (170994/170994), done.
Total 170994 (delta 126176), reused 170524 (delta 125706)
20:18:23.567927 trace.c:414 performance: 3.715349000 s: git command: 'git' 'pack-objects' '--keep-true-parents' '--honor-pack-keep' '--non-empty' '--all' '--reflog' '--unpack-unreachable=2.weeks.ago' '--local' '--delta-base-offset' '.git/objects/pack/.tmp-49190-pack'
20:18:23.584728 trace.c:414 performance: 0.000910000 s: git command: 'git' 'prune-packed'
20:18:23.605218 trace.c:414 performance: 0.017972000 s: git command: 'git' 'update-server-info'
20:18:23.606342 trace.c:414 performance: 3.756312000 s: git command: 'git' 'repack' '-d' '-l' '-A' '--unpack-unreachable=2.weeks.ago'
Checking connectivity: 170994, done.
20:18:25.225424 trace.c:414 performance: 1.616423000 s: git command: 'git' 'prune' '--expire' '2.weeks.ago'
20:18:25.232403 trace.c:414 performance: 0.001051000 s: git command: 'git' 'rerere' 'gc'
20:18:25.233159 trace.c:414 performance: 6.112217000 s: git command: 'git' 'gc'
- GIT_TRACE_SETUP displays the information found by Git about the version library and interactive environment:
$ GIT_TRACE_SETUP=true git status
20:19:47.086765 trace.c:315 setup: git_dir: .git
20:19:47.087184 trace.c:316 setup: worktree: /Users/ben/src/git
20:19:47.087191 trace.c:317 setup: cwd: /Users/ben/src/git
20:19:47.087194 trace.c:318 setup: prefix: (null)
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
9, Others
- If Git is specified_ ssh, GIT when connecting to the ssh host, the specified program will be used instead of ssh, and it will be used with $GIT_SSH [username@]host [-p] is called in command mode, which is not the easiest way to configure customized ssh call mode; It does not support additional command-line arguments, so you must write an encapsulation script and let GIT_SSH points to it. It may be easier to use ~ /. ssh/config.
- GIT_ASKPASS overrides the core.askpass configuration, which is used when Git needs to request authentication from the user. It accepts a text prompt as a command line parameter and returns a response in stdout.
- GIT_NAMESPACE controls the access of references with command space, which is the same as the -- namespace flag. This is mainly useful on the server side. If you want to store multiple fork s of a single version Library in a version library, you can keep the references isolated.
- GIT_FLUSH forces Git to use I/O without cache when writing incrementally to standard output. Set it to 1 to make Git refresh more. Set it to 0 to make all outputs cached. The default value (if this variable is not set) is to select an appropriate caching scheme according to different activities and output modes.
- GIT_REFLOG_ACTION allows you to specify descriptive text to write to reflog, as shown below:
$ GIT_REFLOG_ACTION="my action" git commit --allow-empty -m 'my message'
[master 9e3d55a] my message
$ git reflog -1
9e3d55a HEAD@{0}: my action: my message