章节 ▾ 第二版

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

在本书中,我们介绍了大量的 Git 命令,并尽力以某种叙述方式介绍它们,慢慢地向故事中添加更多的命令。然而,这使得命令的使用示例分散在整本书中。

在本附录中,我们将回顾整本书中提到的所有 Git 命令,并按其用途进行大致分组。我们将讨论每个命令的一般作用,然后指出您可以在本书的哪些地方找到我们使用它的地方。

设置和配置

从 Git 的第一次调用到常见的日常调整和引用,有两个命令被大量使用,即confighelp命令。

git config

Git 有一种默认方式来完成数百件事情。对于很多这些事情,您可以告诉 Git 默认以不同的方式来做,或者设置您的偏好。这包括从告诉 Git 您的姓名到特定的终端颜色偏好或您使用的编辑器。此命令将读取和写入多个文件,因此您可以全局设置值或将其设置为特定存储库的值。

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

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

Git 别名中,我们展示了如何使用它来创建简写命令,这些命令可以扩展为长的选项序列,这样您就不必每次都输入它们。

变基中,我们使用它来使--rebase成为运行git pull时的默认设置。

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

关键字扩展中,我们展示了如何在内容传入和传出 Git 时设置涂抹和清理过滤器。

最后,基本上整个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"

写字板

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 <命令>

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

scroll-to-top