日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Git(10)-merge

發布時間:2023/12/13 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Git(10)-merge 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Merge

  • 1. 無沖突合并
  • 2. 有沖突合并-手動解決
  • 3. git diff in merge
  • 4. 廢棄合并
  • 5. 合并策略

merge相關的操作的命令

git checkout master git merge alternate # 解決沖突 ..... git add file_1 git commit -m "Add slternate line 5, 6" git reset --hard HEAD # before merge commit將工作目錄和索引還原到git merge命令前狀態 git reset --hard ORIG_HEAD # after merge commit 將工作目錄和索引還原到git merge命令前狀態 git checkout -m # 把沖突解決方案搞砸了,想要返回到沖突的原始狀態

合并操作:檢出目標分支->確保工作區干凈->執行合并操作。執行合并操作后,另一個分支不受影響。

1. 無沖突合并

合并不涉及相同文件的相同部分

chenyingying01@cyy merge % git checkout master Switched to branch 'master' chenyingying01@cyy merge % git status On branch master nothing to commit, working tree clean chenyingying01@cyy merge % git merge alternate Merge made by the 'recursive' strategy.file | 1 +1 file changed, 1 insertion(+) chenyingying01@cyy merge % git log --graph --pretty=oneline --abbrev-commit * 50fc402 (HEAD -> master) Merge branch 'alternate' |\ | * 4fb8628 (alternate) Add alternate's line 4 * | 608c235 Another file |/ * 61570a2 Initial 3 line file chenyingying01@cyy merge %

2. 有沖突合并-手動解決

合并涉及相同文件的相同部分, merge時會產生沖突。需要手動的去修改沖突,然后在add, commmit。 代碼分支合并時必須保證合入后不會影響原有的功能。

chenyingying01@cyy merge % git branchalternate * master chenyingying01@cyy merge % cat >> file Line 5 stuff Line 6 stuff chenyingying01@cyy merge % git add file chenyingying01@cyy merge % git commit -m "Add line 5 and line 6" [master f0adb70] Add line 5 and line 61 file changed, 2 insertions(+)chenyingying01@cyy merge % git checkout alternate Switched to branch 'alternate' chenyingying01@cyy merge % cat >> file Line 5 alternate stuff Line 6 alternate stuff chenyingying01@cyy merge % git diff diff --git a/file b/file index 3754bb3..260d21c 100644 --- a/file +++ b/file @@ -2,3 +2,5 @@ line 1 stuffline 2 stuffline 3 stuffline 4 alternate stuff +Line 5 alternate stuff +Line 6 alternate stuff chenyingying01@cyy merge % git add file chenyingying01@cyy merge % git commit -m "Add slternate line 5, 6" line 1 stuff [alternate 8de3d40] Add slternate line 5, 61 file changed, 2 insertions(+)chenyingying01@cyy merge % git checkout master Switched to branch 'master' chenyingying01@cyy merge % git merge alternate Auto-merging file CONFLICT (content): Merge conflict in file Automatic merge failed; fix conflicts and then commit the result. chenyingying01@cyy merge % git diff diff --cc file index f1209a9,260d21c..0000000 --- a/file +++ b/file @@@ -2,5 -2,5 +2,10 @@@ line 1 stufline 2 stuffline 3 stuffline 4 alternate stuff ++<<<<<<< HEAD+Line 5 stuff+Line 6 stuff ++======= + Line 5 alternate stuff + Line 6 alternate stuff ++>>>>>>> alternate chenyingying01@cyy merge % vim file # 手動解決沖突 chenyingying01@cyy merge % git add file chenyingying01@cyy merge % git commit [master b80e372] Create commit 7015896: Merge branch "alternate" chenyingying01@cyy merge % git log --graph --pretty=oneline --abbrev-commit * b80e372 (HEAD -> master) Create commit 7015896: Merge branch "alternate" |\ | * 8de3d40 (alternate) Add slternate line 5, 6 * | f0adb70 Add line 5 and line 6 * | 50fc402 Merge branch 'alternate' |\| | * 4fb8628 Add alternate's line 4 * | 608c235 Another file |/ * 61570a2 Initial 3 line file chenyingying01@cyy merge %

3. git diff in merge

在編程的過程中,提倡使用幾個單獨概念的,定義良好的提交進行merge,而不是等到最后一個大的龐大提交時再merge.
針對有沖突文件,git diff 命令的輸出是 git diff HEAD 和git diff MERGE_HEAD 命令的結果的組合。

chenyingying01@cyy conflict % git diff diff --cc hello index e63164d,562080a..0000000 --- a/hello +++ b/hello @@@ -1,3 -1,3 +1,7 @@@hello ++<<<<<<< HEAD+worlds ++======= + world ++>>>>>>> altYay! chenyingying01@cyy conflict % git diff HEAD diff --git a/hello b/hello index e63164d..1f2f61c 100644 --- a/hello +++ b/hello @@ -1,3 +1,7 @@hello +<<<<<<< HEADworlds +======= +world +>>>>>>> altYay! chenyingying01@cyy conflict % git diff MERGE_HEAD diff --git a/hello b/hello index 562080a..1f2f61c 100644 --- a/hello +++ b/hello @@ -1,3 +1,7 @@hello +<<<<<<< HEAD +worlds +=======world +>>>>>>> altYay!

4. 廢棄合并

# 1.before merge commit 將工作目錄和索引還原到git merge命令前狀態 git reset --hard HEAD # 2.after merge commit 將工作目錄和索引還原到git merge命令前狀態 # ORIG_HEAD git 把原始分支的HEAD放在ORIG_HEAD中 git reset --hard ORIG_HEAD # 3.把沖突解決方案搞砸了,想要返回到沖突的原始狀態 git checkout -m

5. 合并策略

總結

以上是生活随笔為你收集整理的Git(10)-merge的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。