1. 程式人生 > 其它 >Git Pull Failed:You have not concluded your merge.Exiting because of unfinished merge

Git Pull Failed:You have not concluded your merge.Exiting because of unfinished merge

前言

在拉取遠端程式碼時,出現 Git Pull Failed:You have not concluded your merge.Exiting because of unfinished merge。系統提示,可能在pull程式碼之前merge合併失敗。

解決方法

方法一:捨棄原生代碼,遠端版本覆蓋本地版本

使用這種方法之前,可以先將本地修改的程式碼備份一下,避免程式碼重寫。具體命令如下:

git fetch --all

git reset --hard origin/master

git pull

方法二:保留原生代碼,中止合併–>重新合併–>重新拉取

git merge --abort

git reset --merge

git pull

命令解釋

git fetch命令

用於從另一個儲存庫下載物件和引用。遠端跟蹤已更新分支(git術語叫commit),需要將這些更新取回本地,這時就要用到git fetch命令。
語法:git fetch <遠端主機名>。例如:git fetch orgin master,表示取回 origin 主機的 master 分支。更新所有分支,命令可以簡寫為 git fetch

git pull命令

用於取回遠端主機某個分支的更新,再與本地的指定分支合併。這時你可能已經真正明白為什麼會出現拉取失敗的原因了,原因就在於拉取之後的程式碼合併失敗造成的。
語法:git pull <遠端主機名><遠端分支名>:<本地分支名>。例如:git pull origin next:master

,表示取回 origin 主機的 next 分支,與本地的 master 分支合併。如果遠端分支(next)要與當前分支合併,則冒號後面的部分可以省略。

git reset命令

語法:git reset [- -hard|soft|mixed|merge|keep][或HEAD],將當前的分支重新設定到指定的 commit id 或者 HEAD ,其中 HEAD 是預設路徑。其中 hard、soft、mixed、merge、keep是設定的模式。通常使用 --hard,表示自 commit id 以來,工作目錄中的任何改變都被丟棄,並把 HEAD 指向 commit id