[Git专题] 环境搭建

环境搭建

在正式使用 Git 之前,首先应当安装 Git 并完成一些基础配置,本章内容就教大家在 Ubuntu 和 CentOS 上安装 Git 的方法。

如果你使用的是基于 Debian 的 Linux 发行版本,那么应当使用 apt-get 命令来完成安装操作,如下能查到 Git 版本即为安装成功:

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

[jerry@CentOS ~]$ git --version
git version 1.8.1.2

如果你使用的是基于 RPM 的 Linux 发行版本,那么应当使用 yum 命令来完成安装,同样能够用 Git 命令即为安装成功:

$ su -
Password:

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

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

Git 提供 Git 配置工具,让你能设置环境变量。Git 将所有全局变量存储在 .gitconfig 文件中,此文件位于你的家目录下。要设置全局变量,需要加上 --global 选项,如果你不加此选项,你设置的变量将仅能用于当前的 Git 仓库。

你也能设置能在整个系统生效的变量,Git 将这种变量存储在 /etc/gitconfig 文件中,这个文件有适用于该系统中的每个用户和仓库的配置。要设置这些变量值,必须要 root 用户的权限并且应加上 --system 的选项。

如果上述安装完成,您可以进行以下配置工作-

[En]

If the installation above is complete, you can do the following configuration work-

这个设置会用于 Git 的每次提交操作:

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

如上所述,此设置也用于每个提交操作:

[En]

As above, this setting is also used for each commit operation:

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

当你从远端仓库拉取最新修改时,如果这些修改提交彼此冲突,那么 Git 会默认创建合并提交,我们能通过如下的设置来避免此种合并的发生:

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

下面的命令让控制台中的 Git 颜色高亮可用:

[jerry@CentOS ~]$ git config --global color.ui true
[jerry@CentOS ~]$ git config --global color.status auto
[jerry@CentOS ~]$ git config --global color.branch auto

默认情况下,Git 使用系统默认编辑器,它由系统环境变量 VISUALEDITOR 决定。我们也能用 git config 命令自己设置一个喜欢的编辑器,如下即设置 vim 为默认编辑器:

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

Git 并没有提供用于集成冲突修改提交的合并工具,我们通过下述命令可以自己设置一个:

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

要验证自己的设定在本地仓库是否设置,可使用 git config --list 命令来查看:

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

如果所有步骤都遵循上述命令,则显示结果应如下所示:

[En]

If all the steps follow the commands described above, the display results should look like this:

user.name=Jerry
user.email=jerry@tutorialspoint.com
branch.autosetuprebase=always
color.ui=true
color.status=auto
color.branch=auto
core.editor=vim
merge.tool=vimdiff

Original: https://www.cnblogs.com/yychuyu/p/15609034.html
Author: 良许Linux
Title: [Git专题] 环境搭建

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/524327/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球