1、移除旧版本git
Centos自带Git,7.x版本自带git 1.8.3.1,安装新版本之前需要使用yum remove git
卸载
[root@localhost ~]# git --version ##查看git版本##
git version 1.8.3.1
[root@localhost ~]# yum remove git ##卸载自带老版本git##
2、安装git的依赖包
[root@localhost ~]# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
3、下载git源码
[root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.7.3.tar.gz
4、解压git源码
[root@localhost ~]# tar -xvf git-2.7.3.tar.gz
5、配置编译安装
[root@localhost ~]# cd git-2.7.3 ##进入到git-2.7.3安装目录##
[root@localhost git-2.7.3]# make prefix=/root/git all
[root@localhost git-2.7.3]# make prefix=/usr/local/git install
6、配置环境变量(或者创建软连接)
a、查看git安装路径:whereis git
[root@localhost git-2.7.3]# whereis git
git: /usr/local/git /usr/local/git/bin/git
b、配置环境变量:vim /etc/profile
export PATH=/usr/local/git/bin:$PATH:$MAVEN_HOME/bin
c、加载该配置:source /etc/profile
[root@localhost git-2.7.3]# source /etc/profile
7、创建软连接(或者配置环境变量)
[root@localhost bin]# pwd
/bin
[root@localhost bin]# ln -s /usr/local/git/bin/git git
8、查看版本号:git --version
[root@localhost git-2.7.3]# git --version
git version 2.7.3
[root@localhost ~]# mkdir huashan
[root@localhost ~]# cd huashan/
[root@localhost huashan]# git init
初始化空的 Git 版本库于 /root/huashan/.git/
[root@localhost huashan]# git remote add origin https://自己的仓库url地址
[root@localhost huashan]# git remote -v ///查看当前所有HTTPS地址
origin https://github.com/Yuebuqun-666/huashan.git (fetch) ///写回
origin https://github.com/Yuebuqun-666/huashan.git (push) ///推送
[root@localhost huashan]# vim jianfa.txt
华山剑法、填下第一!!!
令说:令狐冲才是最厉害的!!!
令说:我会孤独剑法!!!
大家:真厉害
东方不败:是吗?那我们来试试!!
[root@localhost huashan]# git add jianfa.txt
[root@localhost huashan]# git commit -m "2020-02-03" jianfa.txt
# 位于分支 master
# 未跟踪的文件:
# (使用 "git add ..." 以包含要提交的内容)
#
# huashan/
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
[root@localhost huashan]# git push origin master
Username for 'https://github.com': VillianTsang
Password for 'https://[email protected]':
[root@localhost huashan]# git remote add origin https://自己的仓库url地址
[root@localhost huashan]# git remote -v
origin https://github.com/VillianTsang/huashan.git (fetch)
origin https://github.com/VillianTsang/huashan.git (push)
[root@localhost huashan]# git clone https://自己的仓库url地址
[root@localhost huashan]# ls
huashan.txt jianfa.txt
[root@localhost huashan]# vim jianfa.txt
----------2020-02-03----------
华山剑法、填下第一!!!
令说:令狐冲才是最厉害的!!!
令说:我会孤独剑法!!!
大家:真厉害
东方不败:是吗?那我们来试试!!
----------2020-02-03----------
[root@localhost huashan]# git add jianfa.txt
[root@localhost huashan]# git commit -m "2020-02-03-15:40" jianfa.txt
[root@localhost huashan]# git push origin master
Username for 'https://github.com': 账号用户名
Password for 'https://[email protected]':密码
pull
拉取至本地仓库(或直接用git clone + url
克隆至本地仓库 )[root@localhost huashan]# git pull origin master
[root@localhost huashan]# ls
huashan.txt jianfa.txt
[root@localhost huashan]# git rm -rf --cached huashan.txt
rm 'huashan.txt'
[root@localhost huashan]# git commit -m "2020-02-03-delete"
[root@localhost huashan]# git push -u origin master
Username for 'https://github.com': 用户名
Password for 'https://[email protected]':密码
huashan.txt
文件项目是否已删除