共计 3039 个字符,预计需要花费 8 分钟才能阅读完成。
合并分支,A 分支上合并另一分支 B,则 B 的所有内容都合并到了 A 上,如果分支和主干相差太多,合并就会容易报错,所以通常的操作就是分支合并后就删除分支然后再重新创建分支(完全拷贝主支信息)后再进行后续的合并,依次循环
[ | ]|
master | |
* test | |
[ | ]|
切换到分支 'master' | |
[ | ]|
* master | |
test | |
[ | ]|
Merge made by the 'recursive' strategy. | |
test | 0 | |
1 file changed, 0 insertions(+), 0 deletions(-) | |
create mode 100644 test | |
[ | ]|
e96f03c (HEAD -> master) Merge branch 'test' | |
a6302d6 touch master | |
003e619 (test) touch test | |
f3d6391 add haha | |
2add75e add hello | |
ff77333 aaa | |
dd7925f test head | |
e2e2131 head test | |
644d678 test head | |
326e57a v2 a | |
8f01c62 version2 a | |
a714e37 a | |
47a267c a.txt | |
6ac34be a | |
[ | ]|
a master test | |
冲突合并
[ | ]|
[ | ]|
[add master to a | ]|
1 file changed, 1 insertion(+) | |
[ | ]|
切换到分支 'test' | |
[ | ]|
master | |
* test | |
[ | ]|
haha | |
hello | |
haha | |
[ | ]|
[ | ]|
[add test to a | ]|
1 file changed, 1 insertion(+) | |
[ | ]|
切换到分支 'master' | |
[ | ]|
自动合并 a | |
冲突(内容):合并冲突于 a | |
自动合并失败,修正冲突然后提交修正的结果。[root@zutuanxue git_data] | |
haha | |
hello | |
haha | |
<<<<<<< HEAD | |
master | |
======= | |
test | |
>>>>>>> test | |
[ | ]|
haha | |
hello | |
haha | |
master | |
test | |
[ | ]|
[ | ] merge test to master|
[ | ]|
haha | |
hello | |
haha | |
master | |
test | |
[ | ]|
d8aeb13 (HEAD -> master) merge test to master | |
1cab1b9 (test) add test to a | |
801ff9a add master to a | |
e96f03c Merge branch 'test' | |
a6302d6 touch master | |
003e619 touch test | |
f3d6391 add haha | |
2add75e add hello | |
ff77333 aaa |
如果分支和主干相差太多,合并就会容易报错,所以通常的操作就是分支合并后就删除分支然后再重新创建分支(完全拷贝主支信息)后再进行后续的合并,依次循环
删除分支 git branch -d
[root@zutuanxue git_data]# git branch -d test | |
已删除分支 test(曾为 1cab1b9)。[root@zutuanxue git_data]# git branch | |
* master |
git tag 标签
标签也是指向了一次 commit 提交,是一个里程碑式的标签,回滚打标签直接加标签号,不需要加唯一字符串,不用记唯一字符串,与指针的变动(reset)原理相似,也能通用 git reset –hard 命令
[root@zutuanxue git_data]# git log --oneline | |
d8aeb13 (HEAD -> master) merge test to master | |
1cab1b9 add test to a | |
801ff9a add master to a | |
e96f03c Merge branch 'test' | |
a6302d6 touch master | |
003e619 touch test | |
f3d6391 add haha | |
2add75e add hello | |
[root@zutuanxue git_data]# git tag -a V1.0 f3d6 -m "add haha to V1.0" | |
# 为“add haha”加上一个 V1.0 的标签 - a 指定标签 f3d6 为对应的哈希值,- m 定义描述信息 | |
[root@zutuanxue git_data]# git tag -a V2.0 a630 -m "touch master to V2.0" | |
# 为“touch master”定义一个 V2.0 的标签 | |
[root@zutuanxue git_data]# git tag #查看已有的标签 | |
V1.0 | |
V2.0 | |
[root@zutuanxue git_data]# git show V1.0 #查看指定标签的具体内容 | |
tag V1.0 | |
Tagger: aaa <hello@localhost> | |
Date: Mon Apr 6 04:35:18 2020 -0400 | |
add haha to V1.0 | |
commit f3d6391659db69a5c9fec610b94dd42f827b39e9 (tag: V1.0) | |
Author: aaa <hello@localhost> | |
Date: Mon Apr 6 02:56:34 2020 -0400 | |
add haha | |
diff --git a/a b/a | |
index 5c06d49..ec4f51e 100644 | |
--- a/a | |
+++ b/a | |
@@ -1,2 +1,3 @@ | |
haha | |
hello | |
+haha | |
[root@zutuanxue git_data]# git reset --hard V1.0 #数据回滚到 V1.0 标签的位置 | |
HEAD 现在位于 f3d6391 add haha | |
[root@zutuanxue git_data]# ls | |
a | |
[root@zutuanxue git_data]# cat a | |
haha | |
hello | |
haha | |
[root@zutuanxue git_data]# git tag -d V2.0 #删除标签 | |
已删除标签 'V2.0'(曾为 df79ae8) |
正文完
星哥玩云-微信公众号
