章节 ▾ 第二版

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

在本书中,我们介绍了数十个 Git 命令,并努力以叙述的方式逐步引入更多命令。然而,这导致命令的使用示例分散在全书中。

在本附录中,我们将回顾本书中提到的所有 Git 命令,并大致按其用途分组。我们将简要介绍每个命令的功能,然后指出在本书的何处可以找到其用法。

设置和配置

有两个命令使用频率很高,从 Git 的首次调用到日常调整和引用,它们是 confighelp 命令。

git config

Git 有数百种默认行为。对于其中许多行为,你可以告诉 Git 默认以不同的方式执行它们,或设置你的偏好。这包括从告诉 Git 你的姓名到特定的终端颜色偏好或你使用的编辑器。此命令将从多个文件读取并写入,因此你可以全局设置值或针对特定仓库进行设置。

git config 命令在本书的几乎每个章节中都有使用。

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

Git 别名中,我们展示了如何使用它创建可扩展为长选项序列的快捷命令,这样你就无需每次都输入它们。

变基中,我们使用它使 --rebase 成为你运行 git pull 时的默认选项。

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

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

最后,Git 配置的几乎所有内容都专门介绍此命令。

git config core.editor commands

伴随你的编辑器中的配置说明,许多编辑器可以按如下方式设置

表 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 的更多信息。

scroll-to-top