下载git源码包
查看是否有安装git
已存在git,先卸载再执行以下操作
下载地址:https://github.com/git/git/archive/refs/tags/v2.31.0.zip
下载相关依赖
yum install curl-devel expat-devel openssl-devel zlib-devel gcc
[root@localhost src]# wget https://github.com/git/git/archive/refs/tags/v2.31.0.zip
[root@localhost src]# unzip v2.31.0.zip
[root@localhost src]# cd git-2.31.0
编译安装
make prefix=/usr/local/git install
配置环境变量
cat /etc/profile.d/git.sh
export PATH=$PATH:/usr/local/git/bin
生效环境变量
source /etc/profile.d/git.sh
验证git是否成功安装
[root@localhost profile.d]# git --version
git version 2.31.0
git命令
检查配置信息 git config --list
[root@localhost test]# git config --list
user.name=Yingjian
user.email=jianying@******.com
当没有配置时
配置全局名称 git config --global user.name “name”
配置全局邮箱 git config --global user.email test@163.com
初始化git仓库
[root@localhost opt]# cd project/
[root@localhost project]# ls
[root@localhost project]# git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /opt/project/.git/
指定仓库
git init project
查看仓库当前的状态,显示有变更的文件 git status
比较文件的不同,即暂存区和工作区的差异 git diff
命令 | 说明 |
---|---|
git add | 添加文件到仓库 |
git status | 查看仓库当前的状态,显示有变更的文件 |
git diff | 比较文件的不同,即暂存区和工作区的差异 |
git commit | 提交暂存区到本地仓库 |
git reset | 回退版本 |
git rm | 删除工作区文件 |
git mv | 移动或重命名工作区文件 |
git log | 查看历史提交记录 |
git blame | 以列表形式查看指定文件的历史修改记录 |
git remote | 远程仓库操作 |
git fetch | 从远程获取代码库 |
git pull | 下载远程代码并合并 |
git push | 上传远程代码并合并 |
git branch | 创建分支 |
git checkout | 切换分支 |
git merge | 合并分支 |
本文摘抄自:https://www.cnblogs.com/blange/p/11446253.html