git pull報(bào)錯(cuò):Auto Merge Failed; Fix Conflicts and Then Commit the Result.

1.出錯(cuò)場景:

協(xié)同開發(fā)時(shí),我們從遠(yuǎn)程服務(wù)器上pull下代碼的時(shí)候,出現(xiàn)以下提示信息:
Auto Merge Failed; Fix Conflicts and Then Commit the Result.

2.原因分析:
利用git status,輸出如下:
root@hyk-virt:/etc# git status# On branch master# Your branch and 'origin/master' have diverged,# and have 2 and 2 different commits each, respectively.## Unmerged paths:# (use "git add/rm <file>..." as appropriate to mark resolution)## both modified: apt/sources.list## Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: cups/subscriptions.conf# modified: cups/subscriptions.conf.O# modified: mtab# modified: update-manager/release-upgrades#no changes added to commit (use "git add" and/or "git commit -a")
從git status的結(jié)果可以發(fā)現(xiàn):其中sources.list這個(gè)文件存在合并沖突
而進(jìn)一步分析git pull的原理,實(shí)際上git pull是分了兩步走的,(1)從遠(yuǎn)程pull下origin/master分支(2)將遠(yuǎn)程的origin/master分支與本地master分支進(jìn)行合并
以上的錯(cuò)誤,是出在了第二步驟

3.解決方法

方法一:如果我們確定遠(yuǎn)程的分支正好是我們需要的,而本地的分支上的修改比較陳舊或者不正確,那么可以直接丟棄本地分支內(nèi)容,運(yùn)行如下命令(看需要決定是否需要運(yùn)行g(shù)it fetch取得遠(yuǎn)程分支):
$:git reset --hard origin/master
或者$:git reset --hard ORIG_HEAD
解釋:
git-reset - Reset current HEAD to the specified state
--hard Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
方法二:我們不能丟棄本地修改,因?yàn)槠渲械哪承﹥?nèi)容的確是我們需要的,此時(shí)需要對unmerged的文件進(jìn)行手動(dòng)修改,刪掉其中沖突的部分,然后運(yùn)行如下命令
$:git add filename
$:git commit -m "message"

方法三:如果我們覺得合并以后的文件內(nèi)容比價(jià)混亂,想要廢棄這次合并,回到合并之前的狀態(tài),那么可以運(yùn)行如下命令:
$:git reset --hard HEAD

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 1. 安裝 Github 查看是否安裝git: $ git config --global user.name "...
    Albert_Sun閱讀 13,719評論 9 163
  • 如果repository觸發(fā)了事物機(jī)制,默認(rèn)的配置包括: 特定的數(shù)據(jù)庫的事務(wù)隔離級(jí)別; 沒有timeout配置; ...
    碼頭軍閱讀 232評論 0 0
  • 托學(xué)姐的福,看了《28 歲未成年》點(diǎn)映場,一位少女導(dǎo)演拍了一部講述少女心的故事。 28 歲知性溫柔、百依百順的涼夏...
    口十君閱讀 374評論 0 0
  • 把人生活明白無非有三:遇見的人、讀過的書、走過的路。 遇見的每一個(gè)人都是一種緣份,但并非每一個(gè)人都...
    徐洪均閱讀 325評論 0 2