git無法pull倉庫refusing to merge unrelated histories
- 如果合並了兩個不同的開始提交的倉庫,在新的 git 會發現這兩個倉庫可能不是同一個,為了防止開發者上傳錯誤,於是就給下面的提示:
fatal: refusing to merge unrelated histories
- 如我在Github新建一個倉庫,寫了License,然后把本地一個寫了很久倉庫上傳。這時會發現 github 的倉庫和本地的沒有一個共同的 commit 所以 git 不讓提交,認為是寫錯了 origin ,如果開發者確定是這個 origin 就可以使用 --allow-unrelated-histories 告訴 git 自己確定
- 因為他們是兩個不同的項目,要把兩個不同的項目合並,git需要添加一句代碼,在 git pull 之后,這句代碼是在git 2.9.2版本發生的,最新的版本需要添加 --allow-unrelated-histories 告訴 git 允許不相關歷史合並
- 假如我們的源是origin,分支是master,那么我們需要這樣寫
git pull origin master --allow-unrelated-histories
如果有設置了默認上傳分支就可以用下面代碼