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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Git复习(四)之解决冲突

發布時間:2025/3/15 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Git复习(四)之解决冲突 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

解決沖突

合并分支往往也不是一帆風順的

假設:我們從master創建了一個新的分支feature1更改了最后一行提交,我們切換到master分支也更改了最后一行提交,現在,master分支和feature1分支各自都分別有新的提交,變成了這樣:

這種情況下,Git無法執行“快速合并”,只能試圖把各自的修改合并起來,但這種合并就可能會有沖突,我們試試看:

$ 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告訴我們,readme.txt文件存在沖突,必須手動解決沖突后再提交。git status也可以告訴我們沖突的文件:

$ git status On branch master Your branch is ahead of 'origin/master' by 2 commits.(use "git push" to publish your local commits)You have unmerged paths.(fix conflicts and run "git commit")(use "git merge --abort" to abort the merge)Unmerged paths:(use "git add <file>..." to mark resolution)both modified: readme.txtno changes added to commit (use "git add" and/or "git commit -a")

我們可以直接查看readme.txt的內容:

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

Git用<<<<<<<,=======,>>>>>>>標記出不同分支的內容,我們修改如下后保存:

Creating a new branch is quick and simple.

再提交,現在,master分支和feature1分支變成了下圖所示:

?

總結

當Git無法自動合并分支時,就必須首先解決沖突。解決沖突后,再提交,合并完成。

解決沖突就是把Git合并失敗的文件手動編輯為我們希望的內容,再提交。

?

轉載于:https://www.cnblogs.com/kunmomo/p/11362804.html

總結

以上是生活随笔為你收集整理的Git复习(四)之解决冲突的全部內容,希望文章能夠幫你解決所遇到的問題。

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