可以推广的网站有哪些,com网站域名注册,ui培训排名,怎么给自己的公司建立网站目录
1. 线性分支结构
2. 分叉与合并结构
3. 分支与标签的关系
4. 并行开发与分支管理策略
测试#xff08;本机系统为Rocky_linux9.4#xff09;
合并失败解决
删除分支 删除本地分支
删除远程分支 Git 中的分支结构是版本控制中非常重要的概念之一#xff0c;它描…目录
1. 线性分支结构
2. 分叉与合并结构
3. 分支与标签的关系
4. 并行开发与分支管理策略
测试本机系统为Rocky_linux9.4
合并失败解决
删除分支 删除本地分支
删除远程分支 Git 中的分支结构是版本控制中非常重要的概念之一它描述了项目中不同提交的组织方式和分支之间的关系。以下是Git 分支结构及其解释
1. 线性分支结构
最简单的分支结构是线性的每次提交都是在前一次提交的基础上进行的。这种结构没有分叉或合并所有的提交都在同一个主线上。
A --- B --- C --- D (master)上面的示例中A、B、C、D 表示不同的提交master 分支顺序地指向每个新的提交。 2. 分叉与合并结构
在实际项目中通常会存在多个并行开发的分支这些分支可以同时在不同的特性或修复上工作然后将它们合并回主分支或其他分支。 /--- E --- G (feature1)
A --- B --- C --- D\--- F --- H (feature2) 在上面的示例中feature1 和 feature2 是从 B 提交分叉出来的分支。E 和 F 是各自分支上的提交G 和 H 是将特性分支合并回主分支后的提交。 3. 分支与标签的关系
标签Tag通常用于标记重要的版本发布点或里程碑它们可以指向任意的提交不一定是分支的头部。
A --- B --- C --- D (master, v1.0)\E --- F (v2.0)在这个示例中v1.0 标签指向提交 D表示 v1.0 版本的发布点。而 v2.0 标签指向提交 F表示 v2.0 版本的发布点。 4. 并行开发与分支管理策略 在团队协作中良好的分支管理策略可以有效地管理并行开发和版本控制。常见的策略包括使用主分支如 master作为稳定版本的发布线使用特性分支来开发新功能或修复 bug并通过合并操作将它们整合回主分支。 测试本机系统为Rocky_linux9.4
分支切换
[roottty02 tty]# git branch newrain #创建一个分支
[roottty02 tty]# git branch
* (HEAD detached at ugo)masternewrain
[roottty02 tty]# git checkout newrain #切换到这个分支
Switched to branch newrain
[roottty02 tty]# git branchmaster
* newrain在newrain分支进行修改
[roottty02 tty]# ll
total 0
-rw-r--r-- 1 root root 0 Jul 9 22:37 tty
[roottty02 tty]# echo 1901 tty
[roottty02 tty]# cat tty
1901
[roottty02 tty]# git add .
[roottty02 tty]# git commit -m 1901]
[newrain 96638c2] 1901]1 file changed, 1 insertion()
[roottty02 tty]# git status
On branch newrain
nothing to commit, working tree clean#此时位于分支 newrain 无文件要提交干净的工作区
回到master分支
[roottty02 tty]# git checkout master
Switched to branch master
Your branch is based on origin/master, but the upstream is gone.(use git branch --unset-upstream to fixup)
[roottty02 tty]# git branch
* masternewrain
[roottty02 tty]# ll
total 0
-rw-r--r-- 1 root root 0 Jul 9 23:39 tty
[roottty02 tty]# cat tty #此时在master分支上看不到内容
[roottty02 tty]# git log -1
commit d2470f142c7721ebbff8a3b8f5f7752ecbae67c8 (HEAD - master, tag: v2.0, tag: v1.0, tag: ugo)
Author: Your Name youexample.com
Date: Tue Jul 9 22:35:17 2024 0800commit合并代码
[roottty02 tty]# git merge newrain #合并newrain到当前master分支
Updating d2470f1..96638c2
Fast-forwardtty | 1 1 file changed, 1 insertion()[roottty02 tty]# git status
On branch master
Your branch is based on origin/master, but the upstream is gone.(use git branch --unset-upstream to fixup)nothing to commit, working tree clean[roottty02 tty]# cat tty
1901合并后即可看到内容 合并失败解决
模拟冲突在文件的同一行做不同修改
在master分支进行修改
[roottty02 tty]# cat tty
1901
[roottty02 tty]# echo 1901-git tty
[roottty02 tty]# git add .
[roottty02 tty]# git commit -m newrain 1901-git
[master d343709] newrain 1901-git1 file changed, 1 insertion(), 1 deletion(-)切换到newrain分支
[roottty02 tty]# git checkout newrain
Switched to branch newrain[roottty02 tty]# git branchmaster
* newrain[roottty02 tty]# cat tty
1901[roottty02 tty]# echo newrain tty
[roottty02 tty]# git add .
[roottty02 tty]# git commit -m 1901-git-check
[newrain d32a6f0] 1901-git-check1 file changed, 1 insertion()回到master分区进行合并出现冲突
[roottty02 tty]# git checkout master
Switched to branch master
Your branch is based on origin/master, but the upstream is gone.(use git branch --unset-upstream to fixup)
[roottty02 tty]# git branch
* masternewrain[roottty02 tty]# git merge newrain #此时合并遇到了冲突
Auto-merging tty
CONFLICT (content): Merge conflict in tty
Automatic merge failed; fix conflicts and then commit the result.解决冲突
[roottty02 tty]# cat tty #查看该文件HEAD
1901-git1901
newrainnewrain
解释HEAD
// 当前分支的修改内容// 待合并分支的修改内容newrain编辑该冲突文件手动删除不需要的部分即可
[roottty02 tty]# vim tty #删除后见下图下图就是我要保留的内容 [roottty02 tty]# git add .
[roottty02 tty]# git commit -m 解决合并冲突
[master 47f3b39] 解决合并冲突此时就已经解决该冲突。 删除分支
因为之前已经合并了newrain分支所以现在看到它在列表中。 在这个列表中分支名字前没有 * 号的分支通常可以使用 git branch -d 删除掉刚刚已经将它们的工作整合到了另一个分支所以并不会失去任何东西。查看所有包含未合并工作的分支可以运行 git branch --no-merged
如果真的想要删除分支并丢掉那些工作如同帮助信息里所指出的可以使用 -D 选项强制删除它。 删除本地分支
[roottty02 tty]# git branch #查看分支
* masternewrain[roottty02 tty]# git branch -d newrain #删除这个分支
Deleted branch newrain (was d32a6f0).[roottty02 tty]# git branch #此时就没有了
* master 删除远程分支
如果需要删除远程仓库中的分支可以使用 git push 命令和 --delete 选项
git push origin --delete branch-name
这样就完成了删除分支的操作。在执行任何删除操作之前确保理解并确认删除的分支不再需要并且对删除的后果有清晰的了解。