![](/img/trans.png)
[英]Git: replace commit history of Master with the history of feature branch
[英]Git replace master branch with unrelated history
我的存儲庫中有兩個分支:master和devel。 我試圖將devel合並為master,但出現fatal: refusing to merge unrelated histories
錯誤fatal: refusing to merge unrelated histories
。
在github上,master分支包含一些我不在乎並且不需要合並的文件。 我不需要保留master分支的歷史記錄,我只是想用開發中的東西替換master。
開發好master后,我需要告訴我的伙伴如何拉出master而不合並到他的master本地副本中。
我正在考慮使用的是這篇文章中的建議並運行:
git branch -m master old-master
git branch -m devel master
git push -f origin master
git branch -d old-master
您認為這行得通嗎? 我該如何告訴我的伴侶,以便他獲得最新的母版副本?
自git 2.9起默認行為已更改:
“ git merge”用於允許默認情況下合並沒有共同基礎的兩個分支,這導致創建現有項目的全新歷史記錄,然后由毫無戒心的維護者提取,從而允許不必要的並行歷史記錄合並到現有項目中。 該命令已被告知默認情況下不允許這樣做,在罕見的事件中使用了轉義陰影--allow-unrelated-histories選項,該事件合並了兩個獨立啟動項目的歷史。
有關更多信息,請參見git release changelog 。
您可以使用--allow-unrelated-histories
強制進行合並。
示例: git pull origin branchname --allow-unrelated-histories
您在這里陷入了混亂的局面。
假設您的分行更換順利,您需要詢問您的伴侶是否有任何改變,他不願意單方面支持。
伙伴:
git checkout –b master_tmp master
git checkout master_tmp
git branch –D master
git fecth
git checkout master
#Locate the changes you are missing
git log master_tmp
git cherry pick sha1x…sha1y # look at the documentation of cherry pick.
#Resolve conflicts as usual
git commit
git push
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.