實驗內(nèi)容:在本地庫中建立兩個不同分支,修改同一個文件同一代碼塊,兩分支先后將修改合并到master分支上,master在合并第二個分支代碼時,產(chǎn)生沖突。完成對沖突的修改。
步驟:
(1)master分支
git init #新建一個git環(huán)境
touch mergeTest.txt #在master分支建立文件
vim merteTest.txt #使用vim打開文件加入內(nèi)容 hello master branch!
cat merteTest.txt #查看文件內(nèi)容
git add . #把該文件添加到Git倉庫緩存區(qū)
git commit -m 'master commit' #將緩存區(qū)內(nèi)容添加到本地倉庫的master分區(qū)中
(2)建立兩個分支aBranch,bBranch
git checkout -b bBranch #建立分支bBranch
git checkout -b aBranch #建立分支aBranch
git branch -a #查看所有分支
(3)對建立的分支進行修改提交
?aBranch分支:
cat mergeTest.txt #查看文件
vim mergeTest.txt #使用vim修改文件內(nèi)容hello master-aBranch branch!
git add mergeTest.txt #添加至該分區(qū)緩存區(qū)
git commit -m 'aBranch commit' #從緩存區(qū)提交至該分區(qū)中
?bBranch分支同理進行修改提交。
(4)合并分支后產(chǎn)生沖突
將aBranch分支合并到當(dāng)前master分支上:?git merge:默認(rèn)情況下,Git執(zhí)行“快進式合并”,會? ? 直接將Master分支指向Develop分支。使用--no-ff參數(shù)后,會執(zhí)行正常合并,在Master分支上生? ? ? 成一個新節(jié)點。? ??
git checkout master #切換分支到master
git status #用于顯示工作目錄和暫存區(qū)的狀態(tài)
cat mergeTest.txt
git merge --no-ff aBranch #兩者執(zhí)行正常合并,在Master分支上生成一個新節(jié)點
git merge --no-ff bBranch
(5)解決沖突
?在當(dāng)前分支上(master),找到?jīng)_突文件,直接修改沖突代碼。
cat mergeTest.txt #查看沖突文件
vim mergeTest.txt #vim打開文件修改沖突“hello master-aBranch-bBranch branch!”
#注意一定要刪除沖突符號
cat mergeTest.txt #查看修改后文件內(nèi)容
git add . #添加至緩存區(qū)
git commit -m 'fix conflict commit' #緩存區(qū)中提交至Master分支上生成一個新節(jié)點
git log --graph #查看分支合并的情況,其顯示的結(jié)果中包含每個狀態(tài)點的哈希值
?
?
(6)遇到的問題及解決辦法:
1、執(zhí)行g(shù)it add 時出現(xiàn):warning: in the working copy of ‘.‘, LF will be replaced by?CRLF the? ? ?next?time Git touche問題的解決辦法:
git config --global core.autocrlf true #提交時轉(zhuǎn)換為LF,檢出時轉(zhuǎn)換為CRLF
?2、使用git commit -m ‘**‘命令后顯示Author identity unknown的解決方法:文章來源:http://www.zghlxwxcb.cn/news/detail-465342.html
git config --global user.name '***'
git config --global user.email '***' ? #在進行提交前設(shè)置提交代碼時的用戶信息
?3、使用git branch命令出現(xiàn)fatal: detected dubious ownership in repository at ‘D:/‘的解決方法:文章來源地址http://www.zghlxwxcb.cn/news/detail-465342.html
git config --global --add safe.directory "*";
到了這里,關(guān)于Git 修復(fù)合并沖突(查看和修復(fù))的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!