git分支管理

Git分支管理

标签管理

标签概述

1.同大多数VCS一样,Git也可以对某一时间点上的版本打上标签
2.Git可以给历史中的某一个提交打上标签,以示重要
3.在发布某个软件版本(比如v1.0等等)的时候,经常这么做
4.发布一个版本时,通常先在版本库中打一个标签( tag),这样就唯一确定了打标签时刻的版本。将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来。

列出标签

# 若没有标签 可以自己先打标签
[root@node1 web]# git tag 1.0
[root@node1 web]# git tag
1.0

查找标签

[root@node1 web]# git tag -l '1.0'
1.0

标签分类

轻量标签
轻量标签( lightweight) :它只是一个特定提交的引用
[root@node1 web]# git tag v1.4-lw
[root@node1 web]# git tag 
1.0
v1.0
v1.4-lw
[root@node1 web]# git show v1.4-lw
commit cc5f708c68323f8d3888d0e57905a3960a4ef7a9
Author: csp <1440350254@qq.com>
Date:   Wed Nov 17 02:09:55 2021 -0500

    mv file

diff --git a/index.html b/index.html
new file mode 100644
index 0000000..cfa4dae
--- /dev/null
+++ b/index.html
@@ -0,0 +1 @@
+<h1>hello world sdsa</h1>
diff --git a/index2.html b/index2.html
deleted file mode 100644
index cfa4dae..0000000
--- a/index2.html
+++ /dev/null
@@ -1 +0,0 @@

附注标签
附注标签(annotated) :是存储在Git 数据库中的一个完整对象。其中包含打标签者的名字、电子邮件地址、日期时间;还有一个标签信息;并且可以使用GNU Privacy Guard (GPG)签名与验证

[root@node1 web]# git tag -a v1.4 -m "my vervison 1.4"
[root@node1 web]# git tag
1.0
v1.0
v1.4
v1.4-lw
[root@node1 web]# git show v1.4
tag v1.4
Tagger: csp <1440350254@qq.com>
Date:   Wed Nov 17 21:22:48 2021 -0500

my vervison 1.4

commit cc5f708c68323f8d3888d0e57905a3960a4ef7a9
Author: csp <1440350254@qq.com>
Date:   Wed Nov 17 02:09:55 2021 -0500

    mv file

diff --git a/index.html b/index.html
new file mode 100644
index 0000000..cfa4dae
--- /dev/null
+++ b/index.html
@@ -0,0 +1 @@
+<h1>hello world sdsa</h1>

删除标签

[root@node1 web]# git tag -d v1.4-lw
已删除 tag 'v1.4-lw'(曾为 cc5f708)
[root@node1 web]# git tag
1.0
v1.0
v1.4

Git分支

分支概述

1.几乎所有的版本控制系统都以某种形式支持分支
2.使用分支意味着你可以把你的工作从开发主线上分离开来,以免影响开发主线
3.在很多版本控制系统中,这是一个略微低效的过程
4. Git处理分支的方式可谓是难以置信的轻量,创建新分支这一操作几乎能在瞬间完成
5.在不同分支之间的切换操作也是一样便捷

核心原理

1.当使用git commit进行提交操作时,Git 先计算每一个子目录的校验和
2.然后在Git仓库中这些校验和保存为树对象
3.随后,Git便会创建一个提交对象,它除了包含上面提到的那些信息外,还包含指向这个树对象(项目根目录)的指针
4.如此一来,Git就可以在需要的时候重现此次保存的快照

原理分析

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

1.2Git 的分支,其实本质上仅仅是指向提交对象的可变指针Git 的默认分支名字是master
2.在多次提交操作之后,你其实已经有一个指向最后那个提交对象的 master 分支
3.它会在每次的提交操作中自动向前移动
4.master并不是一个特殊分支,与其他分支没有区别

在这里插入图片描述

查看分支

[root@node1 web]# git branch 
* master

创建分支

[root@node1 web]# git branch 
* master
  testing
# * 代表分支所在的位置

切换分支

[root@node1 web]# git checkout testing 
切换到分支 'testing'
[root@node1 web]# git branch 
  master
* testing

合并分支

[root@node1 web]# git branch
  master
* testing
[root@node1 web]# 
[root@node1 web]# cp /etc/hosts .
[root@node1 web]# ls
11.txt  hosts  index.html
[root@node1 web]# git add .
[root@node1 web]# git commit -m "add hosts"
[root@node1 web]# git checkout master
切换到分支 'master'
[root@node1 web]# ls
11.txt  index.html

显然在testing分支创建文件 在master也找不到,同理在master上创建文件 在testing也是找不到的

[root@node1 web]# cp /etc/passwd .
[root@node1 web]# git add .
[root@node1 web]# git commit -m 'add passwd'
[master 3b5027b] add passwd
 1 file changed, 19 insertions(+)
 create mode 100644 passwd
[root@node1 web]# git log
commit 3b5027b57f7d64edfa881055f1f1a854f7faccae
Author: csp <1440350254@qq.com>
Date:   Wed Nov 17 22:04:18 2021 -0500

    add passwd

commit cc5f708c68323f8d3888d0e57905a3960a4ef7a9
Author: csp <1440350254@qq.com>
Date:   Wed Nov 17 02:09:55 2021 -0500

    mv file

commit 51709f29d1554165111de021a1837451f089e35a
Author: csp <1440350254@qq.com>
Date:   Wed Nov 17 02:04:27 2021 -0500

    rm index.html

commit d698ac795f308f7ceed81e60263361edc27e9ab9
[root@node1 web]# git checkout testing
切换到分支 'testing'
[root@node1 web]# ls
11.txt  hosts  index.html
[root@node1 web]# git log
commit d1f247bb6bc8efff42f88851f8a8ebc065f309f6
Author: csp <1440350254@qq.com>
Date:   Wed Nov 17 21:58:52 2021 -0500

    add hosts

commit cc5f708c68323f8d3888d0e57905a3960a4ef7a9
Author: csp <1440350254@qq.com>
Date:   Wed Nov 17 02:09:55 2021 -0500

    mv file

commit 51709f29d1554165111de021a1837451f089e35a
Author: csp <1440350254@qq.com>
Date:   Wed Nov 17 02:04:27 2021 -0500

    rm index.html

commit d698ac795f308f7ceed81e60263361edc27e9ab9

所以两种分支互不影响 只是指针不同的对象
合并分支

[root@node1 web]# git checkout master 
切换到分支 'master'
[root@node1 web]# git merge testing -m "merge testing"
Merge made by the 'recursive' strategy.
 hosts | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 hosts
[root@node1 web]# ls
11.txt  hosts  index.html  passwd

讲testing分支下hosts文件 搞到主分支上

删除分支

[root@node1 web]# git branch -d testing
已删除分支 testing(曾为 d1f247b)。
[root@node1 web]# git branch 
* master

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值