Git复习(四)之解决冲突
生活随笔
收集整理的這篇文章主要介紹了
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. >>>>>>> feature1Git用<<<<<<<,=======,>>>>>>>標記出不同分支的內容,我們修改如下后保存:
Creating a new branch is quick and simple.再提交,現在,master分支和feature1分支變成了下圖所示:
?
總結
當Git無法自動合并分支時,就必須首先解決沖突。解決沖突后,再提交,合并完成。
解決沖突就是把Git合并失敗的文件手動編輯為我們希望的內容,再提交。
?
轉載于:https://www.cnblogs.com/kunmomo/p/11362804.html
總結
以上是生活随笔為你收集整理的Git复习(四)之解决冲突的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Git复习(三)之分支管理、分支策略
- 下一篇: Git复习(五)之多人协作、git pu