Skip to content

Translate 10-git-internals environment #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 102 additions & 102 deletions book/10-git-internals/sections/environment.asc
Original file line number Diff line number Diff line change
@@ -1,138 +1,138 @@
=== Environment Variables
=== 环境变量

Git always runs inside a `bash` shell, and uses a number of shell environment variables to determine how it behaves.
Occasionally, it comes in handy to know what these are, and how they can be used to make Git behave the way you want it to.
This isn't an exhaustive list of all the environment variables Git pays attention to, but we'll cover the most useful.
Git 总是在一个 `bash` shell 中运行,并借助一些 shell 环境变量来决定它的运行方式。
有时候,知道它们是什么以及它们如何让 Git 按照你想要的方式去运行会很有用。
这里不会列出所有的 Git 环境变量,但我们会涉及最有的那部分。


==== Global Behavior
==== 全局行为

Some of Git's general behavior as a computer program depends on environment variables.
像通常的程序一样,Git 的常规行为依赖于环境变量。

*`GIT_EXEC_PATH`* determines where Git looks for its sub-programs (like `git-commit`, `git-diff`, and others).
You can check the current setting by running `git --exec-path`.
*`GIT_EXEC_PATH`* 决定 Git 到哪找它的子程序 (像 `git-commit`, `git-diff` 等等)。
你可以用 `git --exec-path` 来查看当前设置.

*`HOME`* isn't usually considered customizable (too many other things depend on it), but it's where Git looks for the global configuration file.
If you want a truly portable Git installation, complete with global configuration, you can override `HOME` in the portable Git's shell profile.
通常不会考虑修改 *`HOME`* 这个变量(太多其它东西都依赖它),这是 Git 查找全局配置文件的地方。
如果你想要一个包括全局配置的真正的便携版 Git, 你可以在便携版 Git 的 shell 配置中覆盖 `HOME` 设置。

*`PREFIX`* is similar, but for the system-wide configuration.
Git looks for this file at `$PREFIX/etc/gitconfig`.
*`PREFIX`* 也类似,除了用于系统级别的配置。
Git `$PREFIX/etc/gitconfig` 查找此文件.

*`GIT_CONFIG_NOSYSTEM`*, if set, disables the use of the system-wide configuration file.
This is useful if your system config is interfering with your commands, but you don't have access to change or remove it.
如果设置了 *`GIT_CONFIG_NOSYSTEM`*,就禁用系统级别的配置文件。
这在系统配置影响了你的命令,而你又无权限修改的时候很有用。

*`GIT_PAGER`* controls the program used to display multi-page output on the command line.
If this is unset, `PAGER` will be used as a fallback.
*`GIT_PAGER`* 控制在命令行上显示多页输出的程序。
如果这个没有设置,就会用 `PAGER` .

*`GIT_EDITOR`* is the editor Git will launch when the user needs to edit some text (a commit message, for example).
If unset, `EDITOR` will be used.
*`GIT_EDITOR`* 当用户需要编辑一些文本(比如提交信息)时, Git 会启动这个编辑器。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当用户需要编辑一些文本(比如提交信息)时,Git 会启动 GIT_EDITOR 中指定的编辑器

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同意@IceNature 的说法,默认的编辑器是vim

如果没设置,就会用 `EDITOR`


==== Repository Locations
==== 版本库位置

Git uses several environment variables to determine how it interfaces with the current repository.
Git 用了几个变量来确定它如何与当前版本库交互。

*`GIT_DIR`* is the location of the `.git` folder.
If this isn't specified, Git walks up the directory tree until it gets to `~` or `/`, looking for a `.git` directory at every step.
*`GIT_DIR`* `.git` 目录的位置.
如果这个没有设置, Git 会按照目录树逐层向上查找 `.git` 目录,直到到达 `~` `/`

*`GIT_CEILING_DIRECTORIES`* controls the behavior of searching for a `.git` directory.
If you access directories that are slow to load (such as those on a tape drive, or across a slow network connection), you may want to have Git stop trying earlier than it might otherwise, especially if Git is invoked when building your shell prompt.
*`GIT_CEILING_DIRECTORIES`* 控制查找 `.git` 目录的行为。
如果你访问加载很慢的目录(如那些磁带机上的或通过网络连接访问的),你可能会想让 Git 早点停止尝试,尤其是 shell 构建时调用了 Git

*`GIT_WORK_TREE`* is the location of the root of the working directory for a non-bare repository.
If not specified, the parent directory of `$GIT_DIR` is used.
*`GIT_WORK_TREE`* 是非空版本库的工作目录的根路径
如果没指定,就使用 `$GIT_DIR` 的父目录。

*`GIT_INDEX_FILE`* is the path to the index file (non-bare repositories only).
*`GIT_INDEX_FILE`* 是索引文件的路径(只有非空版本库有)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...(只有非bare版本库有)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vangie bare 不是空版本库的意思吗

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

意思没错,有人翻译成空,有人翻译成裸,bare又正好是git的命令行参数,所以感觉不翻译也可以。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qinglangee bare repository 纯仓库,不是空的,只不过是没有工作目录的仓库。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个肯定要翻译,这里特意强调了一下这点。


*`GIT_OBJECT_DIRECTORY`* can be used to specify the location of the directory that usually resides at `.git/objects`.
*`GIT_OBJECT_DIRECTORY`* 用来指定 `.git/objects` 目录的位置。

*`GIT_ALTERNATE_OBJECT_DIRECTORIES`* is a colon-separated list (formatted like `/dir/one:/dir/two:…`) which tells Git where to check for objects if they aren't in `GIT_OBJECT_DIRECTORY`.
If you happen to have a lot of projects with large files that have the exact same contents, this can be used to avoid storing too many copies of them.
*`GIT_ALTERNATE_OBJECT_DIRECTORIES`* 一个冒号分割的列表 (格式类似 `/dir/one:/dir/two:…`) 用来告诉 Git 到哪里去找不在 `GIT_OBJECT_DIRECTORY` 目录中的对象.
如果你有很多项目有相同内容的大文件,这个可以用来避免存储过多备份。


==== Pathspecs
==== 路径规则

A ``pathspec'' refers to how you specify paths to things in Git, including the use of wildcards.
These are used in the `.gitignore` file, but also on the command-line (`git add *.c`).
所谓 ``pathspec'' 是指你在 Git 中如何指定路径, 包括通配符的使用。
它们会在 `.gitignore` 文件中用到,命令行里也会用到 (`git add *.c`)。

*`GIT_GLOB_PATHSPECS` and `GIT_NOGLOB_PATHSPECS`* control the default behavior of wildcards in pathspecs.
If `GIT_GLOB_PATHSPECS` is set to 1, wildcard characters act as wildcards (which is the default); if `GIT_NOGLOB_PATHSPECS` is set to 1, wildcard characters only match themselves, meaning something like `*.c` would only match a file _named_ ``*.c'', rather than any file whose name ends with `.c`.
You can override this in individual cases by starting the pathspec with `:(glob)` or `:(literal)`, as in `:(glob)*.c`.
*`GIT_GLOB_PATHSPECS` and `GIT_NOGLOB_PATHSPECS`* 控制通配符在路径规则中的默认行为。
如果 `GIT_GLOB_PATHSPECS` 设置为 1, 通配符表现为通配符(这是默认设置); 如果 `GIT_NOGLOB_PATHSPECS` 设置为 1,通配符仅匹配字面。意思是 `*.c` 只会匹配 _文件名是_ ``*.c'' 的文件, 而不是以 `.c` 结尾的文件。
你可以在各个路径规格中用 `:(glob)` `:(literal)` 开头来覆盖这个配置,如 `:(glob)*.c`

*`GIT_LITERAL_PATHSPECS`* disables both of the above behaviors; no wildcard characters will work, and the override prefixes are disabled as well.
*`GIT_LITERAL_PATHSPECS`* 禁用上面的两种行为;通配符将不能用,前缀覆盖也不能用。

*`GIT_ICASE_PATHSPECS`* sets all pathspecs to work in a case-insensitive manner.
*`GIT_ICASE_PATHSPECS`* 让所有的路径规格忽略大小写。


==== Commiting
==== 提交

The final creation of a Git commit object is usually done by `git-commit-tree`, which uses these environment variables as its primary source of information, falling back to configuration values only if these aren't present.
Git 提交对象的创建通常最后是由 `git-commit-tree` 来完成, `git-commit-tree` 用这些环境变量作主要的信息源。 仅当这些值不存在才回退到预置的值。

*`GIT_AUTHOR_NAME`* is the human-readable name in the ``author'' field.
*`GIT_AUTHOR_NAME`* ``author'' 字段的可读的名字。

*`GIT_AUTHOR_EMAIL`* is the email for the ``author'' field.
*`GIT_AUTHOR_EMAIL`* ``author'' 字段的邮件。

*`GIT_AUTHOR_DATE`* is the timestamp used for the ``author'' field.
*`GIT_AUTHOR_DATE`* ``author'' 字段的时间戳。

*`GIT_COMMITTER_NAME`* sets the human name for the ``committer'' field.
*`GIT_COMMITTER_NAME`* ``committer'' 字段的可读的名字。

*`GIT_COMMITTER_EMAIL`* is the email address for the ``committer'' field.
*`GIT_COMMITTER_EMAIL`* ``committer'' 字段的邮件。

*`GIT_COMMITTER_DATE`* is used for the timestamp in the ``committer'' field.
*`GIT_COMMITTER_DATE`* ``committer'' 字段的时间戳。

*`EMAIL`* is the fallback email address in case the `user.email` configuration value isn't set.
If _this_ isn't set, Git falls back to the system user and host names.
如果 `user.email` 没有配置, 就会用到 *`EMAIL`* 指定的邮件地址。
如果 _这个_ 也没有设置, Git 继续回退使用系统用户和主机名。


==== Networking
==== 网络

Git uses the `curl` library to do network operations over HTTP, so *`GIT_CURL_VERBOSE`* tells Git to emit all the messages generated by that library.
This is similar to doing `curl -v` on the command line.
Git 使用 `curl` 库通过 HTTP来完成网络操作, 所以 *`GIT_CURL_VERBOSE`* 告诉 Git 显示所有由那个库产生的消息。
这跟在命令行执行 `curl -v` 差不多。

*`GIT_SSL_NO_VERIFY`* tells Git not to verify SSL certificates.
This can sometimes be necessary if you're using a self-signed certificate to serve Git repositories over HTTPS, or you're in the middle of setting up a Git server but haven't installed a full certificate yet.
*`GIT_SSL_NO_VERIFY`* 告诉 Git 不用验证 SSL 证书。
这在有些时候是需要的, 例如你用一个自己签名的证书通过 HTTPS 来提供 Git 服务, 或者你正在搭建 Git 服务器,还没有安装完全的证书。


If the data rate of an HTTP operation is lower than *`GIT_HTTP_LOW_SPEED_LIMIT`* bytes per second for longer than *`GIT_HTTP_LOW_SPEED_TIME`* seconds, Git will abort that operation.
These values override the `http.lowSpeedLimit` and `http.lowSpeedTime` configuration values.
如果 Git 操作在网速低于 *`GIT_HTTP_LOW_SPEED_LIMIT`* 字节/秒,并且持续 *`GIT_HTTP_LOW_SPEED_TIME`* 秒以上的时间,Git 会终止那个操作。
这些值会覆盖 `http.lowSpeedLimit` `http.lowSpeedTime` 配置的值。

*`GIT_HTTP_USER_AGENT`* sets the user-agent string used by Git when communicating over HTTP.
The default is a value like `git/2.0.0`.
*`GIT_HTTP_USER_AGENT`* 设置 Git 在通过 HTTP 通讯时用到的 user-agent。
默认值类似于 `git/2.0.0`


==== Diffing and Merging
==== 比较和合并

*`GIT_DIFF_OPTS`* is a bit of a misnomer.
The only valid values are `-u<n>` or `--unified=<n>`, which controls the number of context lines shown in a `git diff` command.
*`GIT_DIFF_OPTS`* 这个有点起错名字了
有效值仅支持 `-u<n>` `--unified=<n>`,用来控制在 `git diff` 命令中显示的内容行数。

*`GIT_EXTERNAL_DIFF`* is used as an override for the `diff.external` configuration value.
If it's set, Git will invoke this program when `git diff` is invoked.
*`GIT_EXTERNAL_DIFF`* 用来覆盖 `diff.external` 配置的值。
如果设置了这个值, 当执行Git `git diff` 时,Git 会调用该程序。

*`GIT_DIFF_PATH_COUNTER`* and *`GIT_DIFF_PATH_TOTAL`* are useful from inside the program specified by `GIT_EXTERNAL_DIFF` or `diff.external`.
The former represents which file in a series is being diffed (starting with 1), and the latter is the total number of files in the batch.
*`GIT_DIFF_PATH_COUNTER`* *`GIT_DIFF_PATH_TOTAL`* 对于 `GIT_EXTERNAL_DIFF` `diff.external` 指定的程序有用。
前者表示在一系列文件中哪个是被比较的(从 1 开始),后者表示每批文件的总数。

*`GIT_MERGE_VERBOSITY`* controls the output for the recursive merge strategy.
The allowed values are as follows:
*`GIT_MERGE_VERBOSITY`* 控制递归合并策略的输出。
允许的值有下面这些:

* 0 outputs nothing, except possibly a single error message.
* 1 shows only conflicts.
* 2 also shows file changes.
* 3 shows when files are skipped because they haven't changed.
* 4 shows all paths as they are processed.
* 5 and above show detailed debugging information.
* 0 什么都不输出,除了可能会有一个错误信息。
* 1 只显示冲突。
* 2 还显示文件改变。
* 3 显示因为没有改变被跳过的文件。
* 4 显示处理的所有路径。
* 5 显示详细的调试信息。

The default value is 2.
默认值是 2.

==== Debugging
==== 调试

Want to _really_ know what Git is up to?
Git has a fairly complete set of traces embedded, and all you need to do is turn them on.
The possible values of these variables are as follows:
想 _真正地_ 知道 Git 正在做什么?
Git 内置了相当完整的跟踪信息,你需要做的就是把它们打开。
这些变量的可以用的值如下:

* ``true'', ``1'', or ``2'' – the trace category is written to stderr.
* An absolute path starting with `/` – the trace output will be written to that file.
* ``true'', ``1'', ``2'' – 跟踪类别写到标准错误输出.
* `/` 开头的绝对路径 – 跟踪输出会被写到那个文件。

*`GIT_TRACE`* controls general traces, which don't fit into any specific category.
This includes the expansion of aliases, and delegation to other sub-programs.
*`GIT_TRACE`* 控制常规跟踪,它并不适用于特殊情况。
它跟踪的范围包括别名的展开和其他子程序的委托。

[source,console]
----
Expand All @@ -145,8 +145,8 @@ $ GIT_TRACE=true git lga
20:12:49.899675 run-command.c:192 trace: exec: 'less'
----

*`GIT_TRACE_PACK_ACCESS`* controls tracing of packfile access.
The first field is the packfile being accessed, the second is the offset within that file:
*`GIT_TRACE_PACK_ACCESS`* 控制访问打包文件的跟踪信息
第一个字段是被访问的打包文件,第二个是文件的偏移量:

[source,console]
----
Expand All @@ -162,7 +162,7 @@ Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
----

*`GIT_TRACE_PACKET`* enables packet-level tracing for network operations.
*`GIT_TRACE_PACKET`* 打开网络操作包级别的跟踪信息

[source,console]
----
Expand All @@ -175,8 +175,8 @@ $ GIT_TRACE_PACKET=true git ls-remote origin
# […]
----

*`GIT_TRACE_PERFORMANCE`* controls logging of performance data.
The output shows how long each particular git invocation takes.
*`GIT_TRACE_PERFORMANCE`* 控制性能数据的日志打印。
输出显示了每个 Git 命令调用花费的时间。

[source,console]
----
Expand All @@ -198,7 +198,7 @@ Checking connectivity: 170994, done.
20:18:25.233159 trace.c:414 performance: 6.112217000 s: git command: 'git' 'gc'
----

*`GIT_TRACE_SETUP`* shows information about what Git is discovering about the repository and environment it's interacting with.
*`GIT_TRACE_SETUP`* 显示 Git 发现的关于版本库和交互环境的信息

[source,console]
----
Expand All @@ -212,26 +212,26 @@ Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
----

==== Miscellaneous
==== 其它

*`GIT_SSH`*, if specified, is a program that is invoked instead of `ssh` when Git tries to connect to an SSH host.
It is invoked like `$GIT_SSH [username@]host [-p <port>] <command>`.
Note that this isn't the easiest way to customize how `ssh` is invoked; it won't support extra command-line parameters, so you'd have to write a wrapper script and set `GIT_SSH` to point to it.
It's probably easier just to use the `~/.ssh/config` file for that.
如果指定了 *`GIT_SSH`*, Git 连接 SSH 主机时会用指定的程序代替 `ssh`
它会被用 `$GIT_SSH [username@]host [-p <port>] <command>` 的命令方式调用。
这不是配置定制 `ssh` 调用方式的最简单的方法; 它不支持额外的命令行参数, 所以你必须写一个封装脚本然后让 `GIT_SSH` 指向它。
可能用 `~/.ssh/config` 会更简单。

*`GIT_ASKPASS`* is an override for the `core.askpass` configuration value.
This is the program invoked whenever Git needs to ask the user for credentials, which can expect a text prompt as a command-line argument, and should return the answer on `stdout`.
(See <<_credential_caching>> for more on this subsystem.)
*`GIT_ASKPASS`* 覆盖了 `core.askpass` 配置。
这是 Git 需要向用户请求验证时用到的程序,它接受一个文本提示作为命令行参数,并在 `stdout` 中返回应答。
(查看 <<_credential_caching>>_ 访问更多相关内容)

*`GIT_NAMESPACE`* controls access to namespaced refs, and is equivalent to the `--namespace` flag.
This is mostly useful on the server side, where you may want to store multiple forks of a single repository in one repository, only keeping the refs separate.
*`GIT_NAMESPACE`* 控制有命令空间的引用的访问,与 `--namespace` 标志是相同的.
这主要在服务器端有用, 如果你想在一个版本库中存储单个版本库的多个 fork, 只要保持引用是隔离的就可以。

*`GIT_FLUSH`* can be used to force Git to use non-buffered I/O when writing incrementally to stdout.
A value of 1 causes Git to flush more often, a value of 0 causes all output to be buffered.
The default value (if this variable is not set) is to choose an appropriate buffering scheme depending on the activity and the output mode.
*`GIT_FLUSH`* 强制 Git 在向标准输出增量写入时使用没有缓存的 I/O
设置为 1 让 Git 刷新更多, 设置为 0 则使所有的输出被缓存。
默认值(若此变量未设置)是根据活动和输出模式的不同选择合适的缓存方案。

*`GIT_REFLOG_ACTION`* lets you specify the descriptive text written to the reflog.
Here's an example:
*`GIT_REFLOG_ACTION`* 让你可以指定描述性的文字写到 reflog 中。
这有个例子:

[source,console]
----
Expand Down