理解git中衝突產生的原因
阿新 • • 發佈:2019-01-10
例子一
1.master
新建檔案1.txt。
111
bug code
2.切出功能分支test,此時內容保持不變。同時開發了一點新的功能。
111
bug code
new code int test
3.此時發現:master上的程式碼有bug,緊急修復了bug。
111
fix code in master
4.合併test分支到master,這個時候就會出現衝突。
111 <<<<<<< HEAD fix code in master ======= bug code new code int test >>>>>>> test
出現衝突的原因就是:2行都有修改,合併test時,git不知道你想要哪個
例子2
1.master分支
1.txt
bug code
2.test分支
bug code
new thing in test
3.發現master上有重大bug,切出fix分支修復bug
fix code in fix
4.合併fix到master修復bug
fix code in fix
5.由於test開發完畢,合併test到master
<<<<<<< HEAD fix code in fix ======= bug code new thing in test >>>>>>> test
最佳實踐:
由於master修復了bug,超前了。 所以,與test不同步。 test帶有bug,且開發了新的功能。 這時可以開發完test後,merge到master解決衝突即可。沒什麼可怕的。