git常用的基础命令

一、git常用的基础命令

1.1 git安装 / 配置

yum install git -y
#配置用户信息
git config --global user.name "oldhei"
git config --global user.email "123456@qq.com"
git config --global color.ui true
[root@memcache137 ~]# git config --list
user.name=oldhei
user.email=123456@qq.com
color.ui=true

#配置完后,也可在家目录有对应的git配置信息
[root@memcache137 ~]# cat /root/.gitconfig
[user]
        name = oldhei
        email = 123456@qq.com
[color]
        ui = true

1.2初始化git

cd /root/shellDir/git_data
git init

在这里插入图片描述
在这里插入图片描述

1.3 git 常规使用

在这里插入图片描述

#查看仓库/工作区状态
git status

在这里插入图片描述

touch a b c
git status

在这里插入图片描述

#提交文件a到暂存区域
git add a
#添加目录中所有改动过的文件
git add .

在这里插入图片描述
在上图,有提示指令说,撤出暂存区

#将文件C 撤出暂存区
git rm --cached c

#同时删除工作目录和暂存区文件
git rm -f b

# 提交
git commit -m "commit all file a b c"
#此时再看状态 就是 nothing to commit, working directory clean
git status

在这里插入图片描述

1.4 git修改文件名称方法 git mv

#这里认为
在这里插入图片描述

#改名可这样操作:
git mv a.txt a
git commit -m "modify file a"

1.5 git diff文件比对

# 默认比对工作目录和暂存区有什么不同
git diff
#比对暂存区域和本地仓库
git diff --cached

#如果某个文件已经被仓库管理,如果在此更改此文件,这样写即可
git commit -am "add newfile"

1.6 git log 查看历史提交的信息

#显示详细信息
git log 
#一行式显示信息
git log --oneline
##一行式显示信息且显示当前指针
git log --oneline --decorate

git log -p  #显示具体内容变化
git log -1  #显示一条内容

在这里插入图片描述

1.7 git reset 回滚数据到某一个提交点

git reset --hard d77fdf8

在这里插入图片描述

1.8 git reflog 显示所有历史信息

#显示所有历史信息
git reflog

在这里插入图片描述

1.9 git代码合并

在这里插入图片描述

1.10 git branch创建分支

#查看分支
git branch
#创建一个分支,名为 testing
git branch testing

在这里插入图片描述
做实验:

touch aaa bbb ccc
git add aaa
git commit -m "add aaa"
git add bbb
git commit -m "add bbb"
git add ccc
git commit -m "add ccc"
git log --oneline --decorate

在这里插入图片描述
此时master指向的是"add ccc" 最后一次提交的。 下图是要走的操作
在这里插入图片描述

1.12 git checkout切换分支

git checkout -b testing # 创建并切换到testing分支

git checkout testing
git branch
#删除分支
git branch -d testing

在这里插入图片描述

#切到 testing分支,执行操作
git checkout testing
touch test-ddd
git add .
git commit -m "add new file ddd by testing"

下图可知,现在HEAD指针,是指向testing分支的。
在这里插入图片描述
在这里插入图片描述

#切回master分支
touch master-eee
git add .
git commit -m "add file master-eee"

在这里插入图片描述

1.13 git merge 合并

#切回master分支
git merge testing

此时会弹出下面内容,写注释,然后:wq 保存即可。
在这里插入图片描述
在这里插入图片描述

1.14 git 代码冲突合并

在这里插入图片描述
在这里插入图片描述
此时我们要去修改冲突的文件 a ,删掉/处理/二者都保留内容。
在这里插入图片描述
修改完后 git commit -am "merge testing " 即可
在这里插入图片描述

1.15 git tag 标签使用

在这里插入图片描述

#创建tag  v1.0
git tag -a v1.0 b2ca6be -m "tab v1.0 create "
# 查看所有tag
git tag
#删除标签
git tag -d v1.0

# 查看 v1.0 更改过什么内容
git show v1.0
#利用标签进行回滚
git reset --hard v1.0

小结

在这里插入图片描述
在这里插入图片描述

参考来源:
BV1pJ411R7ci 李老师
朱哥 https://www.zsythink.net/archives/category/%e8%bf%90%e7%bb%b4%e7%9b%b8%e5%85%b3/git

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值