一、Centos安装git
(1)git相关网站
git官网地址
https://git-scm.com/
git相关安装包下载地址
https://mirrors.edge.kernel.org/pub/software/scm/git/
(2)安装相关依赖
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel -y
(3)直接yum安装
yum install git-all -y
(4)查看版本
解释:本机器版本为centos 7.6 所以自带版本为1.8
二、Git初始化
(1)环境变量
Git自带一个git config的工具来帮助设置控制Git外观和行为的配置变量。
①、/etc/gitconfig
该文件包含系统上每一个用户及他们仓库的配置。修改及查看时可以执行
git config --system
但该文件需要管理员或超级用户权限来修改。
②、~/.gitconfig或~/.config/git/config
该文件只针对当前用户。修改和查看时可执行
git config --global
③、当前仓库的Git目录中的config文件,即.git/config
该文件针对于某个仓库。修改和查看可执行
git config --local
在实际过程中,会发现有一些选项会重复出现,因为可能三个文件中都设置了该选项,但三个选项会逐级覆盖。即权力小的覆盖大的。
(2)编辑用户信息(必要)
安装完Git后,就需要设置自己的用户名和邮件地址(原因:每一次提交都需要这些信息)。
git config --global user.name "Lucille"
git config --global user.email "×××××××××××"
三、版本升级
问题描述:在一些与海龟软件等场景联合使用的场景下,版本过低会导致连接不成功,所以会出现升级版本的情况。
解决方案 :下载新的安装包解压即可。
(1)安装依赖
注:此处在yum安装git时,已经进行安装。如果在之前没有进行安装,则需要重新安装。
(2)卸载低版本的git
yum remove git git-all -y
(3)编译安装最新版本的git
cd /usr/local/src
wget https://www.kernel.org/pub/software/scm/git/git-2.33.0.tar.gz
tar -xvf git-2.33.0.tar.gz
cd git-2.33.0
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile
source /etc/profile
(4)重新确认版本
截至此处,版本升级成功!