Git
章節 ▾ 第二版

A3.1 附錄 C:Git 命令 - 設定與配置

在整本書中,我們介紹了數十個 Git 命令,並且盡力在故事脈絡中介紹它們,緩慢地在故事中加入更多命令。然而,這使得命令的使用範例散落在整本書中。

在本附錄中,我們將回顧整本書中提到的所有 Git 命令,並根據它們的用途進行分組。我們將討論每個命令的一般用途,然後指出您可以在本書的何處找到我們使用它的範例。

設定與配置

有兩個命令使用頻率相當高,從 Git 的第一次調用,到日常的調整和參考,即 confighelp 命令。

git config

Git 對數百件事都有預設的處理方式。對於許多事情,您可以告訴 Git 預設以不同的方式處理,或設定您的偏好。這包括從告訴 Git 您的名字到特定的終端機顏色偏好或您使用的編輯器。此命令會讀取和寫入多個檔案,以便您可以全域或針對特定儲存庫設定值。

git config 命令幾乎在本書的每一章都使用過。

首次設定 Git中,我們在開始使用 Git 之前,使用它來指定我們的姓名、電子郵件地址和編輯器偏好。

Git 別名中,我們展示了如何使用它來建立縮寫命令,展開為長選項序列,這樣您就不必每次都輸入它們。

變基中,我們使用它在您執行 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 的資訊。

scroll-to-top