Git - 環境設定



在使用 Git 之前,您必須安裝它並進行一些基本的配置更改。以下是安裝 Ubuntu 和 CentOS Linux 上 Git 客戶端的步驟。

Git 客戶端安裝

如果您使用的是基於 Debian 的 GNU/Linux 發行版,則apt-get 命令將完成此操作。

[ubuntu ~]$ sudo apt-get install git-core
[sudo] password for ubuntu:

[ubuntu ~]$ git --version
git version 1.8.1.2

如果您使用的是基於 RPM 的 GNU/Linux 發行版,則使用以下所示的yum 命令。

[CentOS ~]$
su -
Password:

[CentOS ~]# yum -y install git-core

[CentOS ~]# git --version
git version 1.7.1

自定義 Git 環境

Git 提供了 git config 工具,允許您設定配置變數。Git 將所有全域性配置儲存在.gitconfig 檔案中,該檔案位於您的主目錄中。要將這些配置值設定為全域性值,請新增--global 選項,如果您省略--global 選項,則您的配置特定於當前 Git 倉庫。

您還可以設定系統範圍的配置。Git 將這些值儲存在/etc/gitconfig 檔案中,該檔案包含系統上每個使用者和倉庫的配置。要設定這些值,您必須具有 root 許可權並使用--system 選項。

編譯並執行上述程式碼後,將產生以下結果:

設定使用者名稱

此資訊由 Git 用於每次提交。

[jerry@CentOS project]$ git config --global user.name "Jerry Mouse"

設定郵箱地址

此資訊由 Git 用於每次提交。

[jerry@CentOS project]$ git config --global user.email "jerry@tutorialspoint.com"

避免拉取時的合併提交

您從遠端倉庫拉取最新的更改,如果這些更改存在差異,則 Git 預設會建立合併提交。我們可以透過以下設定避免這種情況。

jerry@CentOS project]$ git config --global branch.autosetuprebase always

顏色高亮

以下命令啟用控制檯中 Git 的顏色高亮。

[jerry@CentOS project]$ git config --global color.ui true

[jerry@CentOS project]$ git config --global color.status auto

[jerry@CentOS project]$ git config --global color.branch auto

設定預設編輯器

預設情況下,Git 使用系統預設編輯器,該編輯器取自 VISUAL 或 EDITOR 環境變數。我們可以使用 git config 配置不同的編輯器。

[jerry@CentOS project]$ git config --global core.editor vim

設定預設合併工具

Git 沒有提供用於將衝突更改整合到工作樹中的預設合併工具。我們可以透過啟用以下設定來設定預設合併工具。

[jerry@CentOS project]$ git config --global merge.tool vimdiff

列出 Git 設定

要驗證本地倉庫的 Git 設定,請使用以下所示的git config –list 命令。

[jerry@CentOS ~]$ git config --list

上述命令將產生以下結果。

user.name=Jerry Mouse
user.email=jerry@tutorialspoint.com
push.default=nothing
branch.autosetuprebase=always
color.ui=true
color.status=auto
color.branch=auto
core.editor=vim
merge.tool=vimdiff
廣告
© . All rights reserved.