git 工作区_暂存区_仓库_分支管理_合并分支_打标签
二、git仓库的应用
1、创建git仓库
1)创建git仓库根目录
[root@centos01 ~]# mkdir git_dat
2)初始化git仓库
[root@centos01 ~]# cd git_date/
[root@centos01 git_date]# git init
3)配置管理git仓库用户
[root@centos01 git_date]# git config --global user.name "bob"
[root@centos01 git_date]# git config --global user.email "bob@benet.com"
[root@centos01 git_date]# git config --global color.ui true
2、暂存区的管理
1)查看git状态
[root@centos01 git_date]# git status
2)git仓库创建文件
[root@centos01 git_date]# touch 1.txt
3)将文件1.txt提交到暂存区
[root@centos01 git_date]# git add 1.txt
4)从暂存区删除
[root@centos01 git_date]# git rm --cached 1.txt
5)提交所有文件
[root@centos01 git_date]# git add .
3、git数据提交
1)提交单个文件到git仓库
[root@centos01 git_date]# git commit 1.txt -m 'new 1.txt'
2)提交暂存区的所有文件到git仓库
[root@centos01 git_date]# git commit . -m 'new 2.txt and 3.txt'
3)从暂存区和工作区删除数据
[root@centos01 git_date]# git rm -f 4.txt
4、比较工作区文件区别
1)工作区创建文件
[root@centos01 git_date]# echo "aaa" > a.txt
[root@centos01 git_date]# echo "bbb" > b.txt
2)比较工作区文件区别
[root@centos01 git_date]# diff a.txt b.txt
5、比较暂存区文件区别
1)提交数据到暂存区
[root@centos01 git_date]# git add .
2)比较暂存区文件区别a.txt和b.txt文件区别
[root@centos01 git_date]# git diff --cached a.txt b.txt
3)比较暂存区所有文件区别
[root@centos01 git_date]# git diff --cached
6、修改暂存区数据
1)修改数据a.txt为aa.txt
[root@centos01 git_date]# mv a.txt aa.txt
2)删除原文件a.txt
[root@centos01 git_date]# git rm --cached a.txt
3)git mv修改并删除原数据
[root@centos01 git_date]# git mv b.txt bb.txt
三、git日志管理,git回滚,git分支管理
1、git日志的管理
1)查看所有的git日志
[root@centos01 git_date]# git log
2)将日志进行缩进显示为一行,日志ID长度缩进7位
[root@centos01 git_date]# git log --oneline
3)显示最后一次修改的指针信息
[root@centos01 git_date]# git log --oneline --decorate
4)显示最新的日志,选项是数字1
[root@centos01 git_date]# git log -1
5)查看最新日志改动信息
[root@centos01 git_date]# git log -1 -p
2、配置数据回滚
1)查看数据指针信息
[root@centos01 git_date]# git log --oneline --decorate
2)回滚数据,可以从新版本回滚到旧版本,不能从旧版本回滚到新版本
[root@centos01 git_date]# git reset --hard 682e7f9
3、git分支的管理
1)创建分支benet
[root@centos01 git_date]# git branch benet
2)查看分支
[root@centos01 git_date]# git branch
3)切换分支
[root@centos01 git_date]# git checkout benet
4)创建文件并提交到benet分支中
[root@centos01 git_date]# touch yun01.txt
[root@centos01 git_date]# git add yun01.txt
[root@centos01 git_date]# git commit -m 'new yun01.txt'
4、合并分支数据
1)切换到master分支
[root@centos01 git_date]# git checkout master
2)将benet分支合并到master中
[root@centos01 git_date]# git merge benet
3)删除分支benet
[root@centos01 git_date]# git branch -d benet
5、git打标签
1)git标签的作用
区分开发板或者稳定版
一般管理员对稳定版项目打标签
当基于稳定版继续开发新版本将变成开发版
当在测试开发版项目过程中发现版本有问题可以根据标签进行回滚
2)获取项目的标签
[root@centos01 git_data]# git log --oneline
3)对新版本数据打标签
[root@centos01 git_data]# git tag -a v1.0 f5fca60 -m '第一个稳定版本'
4)查看版本ID
[root@centos01 git_data]# git tag
5)查看标识的详细信息
[root@centos01 git_data]# git show v1.0
6)回滚到标签版本
[root@centos01 git_data]# git reset --hard v1.0
7)删除标签
[root@centos01 git_data]# git tag -d v1.0

浙公网安备 33010602011771号