1. 程式人生 > 其它 >|NO.Z.00008|——————————|^^ 配置 ^^|——|CI/CD&Git配置.V07|---------------------------------------------------------|Git衝突解決|

|NO.Z.00008|——————————|^^ 配置 ^^|——|CI/CD&Git配置.V07|---------------------------------------------------------|Git衝突解決|



[CloudNative:CI/CD&Git配置.V07]                                                                          [Applications.CloudNative] [|CI/CD|分散式版本控制系統|**3節點**|Jenkins|Git|——|git.server|git.client|ssh|] [Git架構圖|GIt概念|Git專案互動|Git常用命令|http|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).








===============================END===============================


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



來自為知筆記(Wiz)