git合並不同倉庫下的分支


1.把lib合並到pro

$ git remote -v
origin  git@192.168.1.1:lib.git (fetch) origin git@192.168.1.1:lib.git (push) $ git remote -v origin git@192.168.1.1:pro.git (fetch) origin git@192.168.1.1:pro.git (push)

 

2.把一個遠程倉庫添加到另一個倉庫中

在pro的分支下運行上面的命令,把lib遠程倉庫添加到pro下,昵稱是slib

$ git remote add slib git@192.168.1.1:lib.git


3.拉取倉庫代碼到本地

把代碼拉到本地

$ git fetch slib

 

4.切出一個需要合並的新添加的遠程倉庫的分支

把本地拉取的lib的倉庫,切換到一個test分支,防止合並沖突不好解決

$ git checkout -b test slib/master


如果報下面的錯誤,說明你的slib對應的遠程倉庫沒有對應的分支master,需要你先創建一個push上去,然后再運行上面的fetch

fatal: 'slib/master' is not a commit and a branch 'test' cannot be created from it

 

 5.合並

如果要把新分支內容合並到老分支,就切到老分支合並,如果是把老分支的內容合並到新分支,就直接合並。

切回到pro的一個分支

$ git checkout prodev
Checking out files: 100% (14522/14522), done. Switched to branch 'prodev'

 

把test merge過來,就可以了,可能會有錯誤

$ git merge test
fatal: refusing to merge unrelated histories


添加命令,強制merge過來
解決沖突提交,就可以了

$ git merge test --allow-unrelated-histories
Auto-merging .gitignore CONFLICT (add/add): Merge conflict in .gitignore Automatic merge failed; fix conflicts and then commit the result.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM