|NO.Z.00008|——————————|^^ 配置 ^^|——|CI/CD&Git配置.V07|——|Git冲突解决|

一、Git常用命令——解决冲突
### --- 创建feature1分支并提交版本
~~~     创建feature1分支

[root@server12 shell]# git checkout -b feature1          # 创建新的feature1分支
### --- 修改内容,修改readme.txt最后一行,改为:

[root@server12 shell]# vim readme.txt
Creating a new branch is quick AND simple.
### --- 提交分支

[root@server12 shell]#  git add readme.txt               # 在feature1分支上提交
[root@server12 shell]# git commit -m "AND simple"
[feature1 0c34577] AND simple
 1 file changed, 1 insertion(+)
 create mode 100644 readme.txt
二、切换到master分支
### --- 切换到master分支

[root@server12 shell]#  git checkout master               # 切换到master分支
Switched to branch 'master'  
### --- 查看分支记录
~~~     Git还会自动提示我们当前master分支比远程的master分支要超前1个提交。

[root@server12 shell]#  git branch 
  feature1
* master
### --- 在master分支上把readme.txt文件的最后一行改为:

[root@server12 shell]# vim readme.txt
Creating a new branch is quick & simple.
### --- 将修改后的分支内容提交

[root@server12 shell]# git add readme.txt
[root@server12 shell]# git commit -m "& simple"
[master b68fcb2] & simple
 1 file changed, 1 insertion(+)
 create mode 100644 readme.txt
三、分支合并
### --- 现在,master分支和feature1分支各自都分别有新的提交
~~~     这种情况下,Git无法执行“快速合并”,只能试图把各自的修改合并起来,
~~~     但这种合并就可能会有冲突,我们试试看:
~~~     readme.txt文件存在冲突,必须手动解决冲突后再提交。

git merge feature1 Auto-merging readme.txt CONFLICT (content):
Merge conflict in readme.txt Automatic merge failed;
fix conflicts and then commit the result.
四、解决冲突
### --- 查看冲突的文件并修改冲突文件
~~~     Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容,我们修改后保存再提交:

[root@server12 shell]# git status                       # 可以显示冲突的文件;
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
<<<<<<< HEAD Creating a new branch is quick & simple. ======= Creating a new branch is quick AND simple. >>>>>>> feature1
### --- 重新提交

[root@server12 shell]# git add readme.txt 
[root@server12 shell]# git commit -m "conflict fixed"
[master 59bc1cb] conflict fixed
五、删除feature1分支
### --- 最后,删除feature1分支:

[root@server12 shell]# git branch -D feature1
Deleted branch feature1 (was 0c34577).

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(31)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示