有两个十分常用的命令:config
和 help
。从第一次调用 Git 到日常微调及阅读参考,它们一直陪伴着你。
git config
Git 做的很多工作都有一种默认方式。 对于绝大多数工作而言,你可以改变 Git 的默认方式,或者根据你的偏好来设置。 这些设置涵盖了所有的事,从告诉 Git 你的名字,到指定偏好的终端颜色,以及你使用的编辑器。 此命令会从几个特定的配置文件中读取和写入配置值,以便你可以从全局或者针对特定的仓库来进行设置。
本书几乎所有的章节都用到了 git config
命令。
在 初次运行 Git 前的配置 一节中,在开始使用 Git 之前,我们用它来指定我们的名字,邮箱地址和编辑器偏好。
在 Git 别名 一节中我们展示了如何创建可以展开为长选项序列的短命令,以便你不用每次都输入它们。
在 变基 一节中,执行 git pull
命令时,使用此命令来将 --rebase
作为默认选项。
在 凭证存储 一节中,我们使用它来为你的 HTTP 密码设置一个默认的存储区域。
在 关键字展开 一节中我们展示了如何设置在 Git 的内容添加和减少时使用的 smudge 过滤器 和 clean 过滤器。
最后,基本上 配置 Git 整个章节都是针对此命令的。
git config core.editor 命令
就像 初次运行 Git 前的配置 里的设置指示,很多编辑器可以如下设置:
Table 5. 详细的 core.editor
设置命令列表
编辑器 | 设置命令 |
---|---|
Atom |
|
git config --global core.editor "atom --wait"
| |
BBEdit (macOS, with command line tools)
|
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-bit)
|
git config --global core.editor "'C:\Program Files\Vim\vim72\gvim.exe' --nofork '%*'"
(Also see note below)
| |
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-bit)
|
git config core.editor notepad
| |
Notepad++ (Windows 64-bit)
|
git config --global core.editor "'C:\Program Files\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
(Also see note below)
| |
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-bit)
|
git config --global core.editor "'C:\Program Files\Sublime Text 3\sublime_text.exe' -w"
(Also see note below)
| |
TextEdit (macOS)
|
git config --global core.editor "open --wait-apps --new -e"
| |
Textmate
|
git config --global core.editor "mate -w"
| |
Textpad (Windows 64-bit)
|
git config --global core.editor "'C:\Program Files\TextPad 5\TextPad.exe' -m"
(Also see note below)
| |
UltraEdit (Windows 64-bit)
|
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 (Free/Libre Open Source Software Binaries of 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"
|
如果你在 64 位 Windows 系统上安装了 32 位的编辑器,那么它会被安装在 |
git help
git help
命令用来显示任何命令的 Git 自带文档。 但是我们仅会在此附录中提到大部分最常用的命令,对于每一个命令的完整的可选项及标志列表,你可以随时运行 git help <command>
命令来了解。
我们在 获取帮助 一节中介绍了 git help
命令,同时在 配置服务器 一节中给你展示了如何使用它来查找更多关于 git shell
的信息。