章节 ▾ 第二版

A3.1 附录 C:Git 命令 - 设置和配置

在本书中,我们介绍了数十个 Git 命令,并努力将它们融入到某种叙事中,逐渐添加更多命令。然而,这使得命令的使用示例在整本书中有些零散。

在本附录中,我们将回顾本书中介绍的所有 Git 命令,并大致按用途进行分组。我们将大致介绍每个命令的作用,然后指出你在书中什么地方可以使用它。

设置和配置

有两个命令被使用得非常频繁,从 Git 的首次调用到日常的微调和引用,它们就是 confighelp 命令。

git config

Git 有一个默认的处理数百种事情的方式。对于其中的许多事情,你可以告诉 Git 采用不同的默认方式来处理,或者设置你的偏好。这包括从告诉 Git 你的名字是什么,到特定的终端颜色偏好,或者你使用的编辑器。该命令会从多个文件中读取和写入,因此你可以全局设置值,也可以针对特定仓库设置。

git config 命令在本书的几乎每一章中都被使用过。

首次 Git 设置 中,我们在开始使用 Git 之前,使用它来指定我们的名字、电子邮件地址和编辑器偏好。

Git 别名 中,我们展示了如何使用它来创建简短的命令,这些命令可以展开成长选项序列,这样你就无需每次都输入它们。

Rebasing 中,我们使用它来使 git pull 命令的默认行为是 --rebase

凭据存储 中,我们使用它来设置 HTTP 密码的默认存储方式。

关键字扩展 中,我们展示了如何为进出 Git 的内容设置 smudge 和 clean 过滤器。

最后,基本上 Git 配置 的整个章节都专门介绍这个命令。

git config core.editor 命令

你的编辑器 中,除了配置说明之外,许多编辑器都可以按以下方式设置:

表 4. core.editor 配置命令的详尽列表
编辑器 配置命令

Atom

git config --global core.editor "atom --wait"

BBEdit (macOS, 带有命令行工具)

git config --global core.editor "bbedit -w"

Emacs

git config --global core.editor emacs

Gedit (Linux)

git config --global core.editor "gedit --wait --new-window"

Gvim (Windows 64位)

git config --global core.editor "'C:\Program Files\Vim\vim72\gvim.exe' --nofork '%*'" (另请参阅下方的说明)

Helix

git config --global core.editor "hx"

Kate (Linux)

git config --global core.editor "kate --block"

nano

git config --global core.editor "nano -w"

Notepad (Windows 64位)

git config core.editor notepad

Notepad++ (Windows 64位)

git config --global core.editor "'C:\Program Files\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin" (另请参阅下方的说明)

Scratch (Linux)

git config --global core.editor "scratch-text-editor"

Sublime Text (macOS)

git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl --new-window --wait"

Sublime Text (Windows 64位)

git config --global core.editor "'C:\Program Files\Sublime Text 3\sublime_text.exe' -w" (另请参阅下方的说明)

TextEdit (macOS)

git config --global core.editor "open --wait-apps --new -e"

Textmate

git config --global core.editor "mate -w"

Textpad (Windows 64位)

git config --global core.editor "'C:\Program Files\TextPad 5\TextPad.exe' -m" (另请参阅下方的说明)

UltraEdit (Windows 64位)

git config --global core.editor Uedit32

Vim

git config --global core.editor "vim --nofork"

Visual Studio Code

git config --global core.editor "code --wait"

VSCodium (VSCode 的免费/开源软件二进制文件)

git config --global core.editor "codium --wait"

WordPad

git config --global core.editor "'C:\Program Files\Windows NT\Accessories\wordpad.exe'"

Xi

git config --global core.editor "xi --wait"

注意

如果您在 Windows 64 位系统上使用的是 32 位编辑器,则程序将安装在 C:\Program Files (x86)\ 目录中,而不是上表中所示的 C:\Program Files\ 目录。

git help

git help 命令用于显示 Git 附带的关于任何命令的全部文档。虽然本附录将粗略概述其中一些较受欢迎的命令,但要获取每个命令所有可能选项和标志的完整列表,您可以随时运行 git help <command>

我们在 获取帮助 中介绍了 git help 命令,并在 设置服务器 中向您展示了如何使用它来查找有关 git shell 的更多信息。