git安装及相关命令

git安装

[root@localhost ~]# yum install git -y

[root@localhost ~]# git --version

配置文件,用命令写,手动写也可以
 

[root@localhost ~]# git config --global user.name "zjs"

[root@localhost ~]# git config --global user.email "1163317488@qq.com"

[root@localhost ~]# git config --global user.color.ui true

[root@localhost ~]# cat .gitconfig

[user]

name = zjs

email = 1163317488@qq.com

[user "color"]

ui = true

创建本地仓库(必须是创建仓库目录才可以执行git相关操作)
 

[root@localhost ~]# mkdir demo

[root@localhost ~]# cd demo/

[root@localhost demo]# git init

Initialized empty Git repository in /root/demo/.git/

[root@localhost demo]# ls .git/

branches config description HEAD hooks info objects refs

(不要修改.git/目录下面的东西)

上传文件到暂存区再到本地仓库

[root@localhost demo]# touch file1 file2 file3

[root@localhost demo]# git add .

[root@localhost demo]# git status

[root@localhost demo]# git commit -m "test"

把之前上传到仓库的版本覆盖回暂存区,再覆盖回本地目录

[root@localhost demo]# git reset aaa

Unstaged changes after reset:

M aaa

[root@localhost demo]# git checkout aaa

 

对比本地目录和暂存区是否一致

[root@localhost demo]# git diff aaa

diff --git a/aaa b/aaa

index 46dbb1f..78ed5d0 100644

--- a/aaa

+++ b/aaa

@@ -1 +1 @@

-file12345

+adsdile12345

[root@localhost demo]# git add .

对比暂存区和存储区是否一致

[root@localhost demo]# git diff --cached aaa

diff --git a/aaa b/aaa

index 46dbb1f..78ed5d0 100644

--- a/aaa

+++ b/aaa

@@ -1 +1 @@

-file12345

+adsdile12345

创建分支,创建时,本地目录下的文件也会被复制到分支下

 

[root@localhost demo]# git branch devops

查看分支

 

[root@localhost demo]# git branch

devops

    master

切换分支

[root@localhost demo]# git checkout master

分支版本合并

先把master的内容合并过来到devops,再测试,没问题再切回master分支,把devops的内容合并到master。

[root@localhost demo]# git merge master

###测试

[root@localhost demo]# git checkout master

[root@localhost demo]# git merge devops

开发测试完成后删除相应分支
 

[root@localhost demo]# git branch -d devops

Deleted branch devops (was 0964ac4).

[root@localhost demo]# git branch

* master

 *分支合并时 ,出现冲突,需要手动修改

git标签

1.git标签作什么用?

当Git仓库内的数据有改善或者功能更新时,我们经常会打一个类似于软件版本号的标签tag,这样通过标签就可以将版本库中的某个版本给记录下来,便于我们后续将特定时期的数据取出来用。简单来说:标签也是版本库的一个照。

2.为什么要使用git标签?

Git有commit,为什么还要引入tag?

“请把上周一的那个版本打包发布,commit号是6a5819e...”,“一串乱七八糟的数字不好找!”

如果换一个办法:

“请把上周一的那个版本打包发布,版本号是v1.2”,按照tag v1.2查找commit就行,

所以,tag就是一个让人容易记住的名字,它跟某个commit绑在一起。

获取完整commit id
[root@localhost demo]# git rev-parse HEAD
59039973b8836138fd93ddbd50db55746dd55a8a
新建当前commit id的标签
[root@localhost demo]# git tag v1.1 -m "备注"
新建指定commit id的标签
[root@localhost demo]# git tag v1.3 5903997 -m "备注"
显示当前分支的最近几次提交
[root@localhost demo]# git reflog
查看所有标签
[root@localhost demo]# git tag
查看标签的信息
[root@localhost demo]# git show v1.1
删除本地tag
[root@localhost demo]# git tag -d v1.1

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值