git安装与使用(centos)

下载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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值