我正在使用BitBucket.Already我推了一個分支來掌握並與master.Now合併,現在我需要恢復從master.推薦的分支做到這一點?如何恢復從主的合併分支?
在我的情況:我必須恢復最後五個提交,我需要返回以前的代碼。如何刪除或恢復提交?
注意:目前我沒有任何分支,因爲已經與主合併並刪除了分支。我只有一個主分支。
是否有可能再次恢復合併分支?
我正在使用BitBucket.Already我推了一個分支來掌握並與master.Now合併,現在我需要恢復從master.推薦的分支做到這一點?如何恢復從主的合併分支?
在我的情況:我必須恢復最後五個提交,我需要返回以前的代碼。如何刪除或恢復提交?
注意:目前我沒有任何分支,因爲已經與主合併並刪除了分支。我只有一個主分支。
是否有可能再次恢復合併分支?
好的,所以你需要做一個強制推動來解決這個問題。我不會做合併的回覆,這會給你帶來問題。請注意,強制推送意味着您正在重寫歷史記錄,因此您需要讓其他開發人員知道您正在執行此操作。
1./ reset master back to the master side parent commit
2./ recover your private branch, so you don't lose your commits.
3./ force push master.
此圖有希望說清楚。
感謝您的幫助..我解決了 –
這將有助於瞭解您的歷史是什麼樣子。我將使用的地牢抓取的歷史作爲一個例子,告訴你如何撤消合併提交:
比方說,它目前看起來是這樣的:
$ git log --graph --online --decorate -n 5
* 94e1b85 (HEAD, master) Merge branch 'next'
|\
| * 9312efc Don't generate Lehudib's crystal spear the unrand.
| * 518382a Make Sticks to Snakes only work on missiles
| * 6e8ccac Let monsters pick up Elf:$ loot
* | 9ca6e02 Distinct manual tiles
* | a16bb39 Restore trunk changelog entries removed by 673ecc60.
* | 1d9921b Touch the 0.13 changelog header with the tentative release date.
你會發現git log --oneline --graph --decorate
用武之地了。 --graph
將幫助你看到分支&合併,--oneline
只是保持簡短,--decorate
將分支和標籤名稱註釋到提交。 (這是一個非常有用的命令,我爲此稍微定製了一個版本的別名。)
看到94e1b85
提交?這是一個合併提交。假設我們想撤消它。讓我們備份的東西,以防萬一:
# Save master, just in case:
$ git checkout master
$ git branch old-master
首先,讓我們恢復舊的分支。我打算叫它other-branch
。或者:
$ git branch other-branch master^2
這意味着「創建一個名爲other-branch
新的分支,在提交這是master
第二(2
)父(^
)你也可以通過哈希,你可以看到它命名。在git log
命令我上面使用
$ git branch other-branch 9312efc
歷史應該像:
$ git log --graph --online --decorate -n 5
* 94e1b85 (HEAD, master) Merge branch 'next'
|\
| * 9312efc (other-branch) Don't generate Lehudib's crystal spear the unrand.
| * 518382a Make Sticks to Snakes only work on missiles
| * 6e8ccac Let monsters pick up Elf:$ loot
* | 9ca6e02 Distinct manual tiles
* | a16bb39 Restore trunk changelog entries removed by 673ecc60.
* | 1d9921b Touch the 0.13 changelog header with the tentative release date.
現在,更改其中master
點:
$ git checkout master $$ git reset --hard HEAD^
(你可以提交哈希更換HEAD^
這裏。在^
之後有一個隱含的1
。)
請與您的工作:
$ git log --oneline --graph -n 120 --decorate old-master
* 94e1b85 (old-master) Merge branch 'next'
|\
| * 9312efc (other-branch) Don't generate Lehudib's crystal spear the unrand.
| * 518382a Make Sticks to Snakes only work on missiles
| * 6e8ccac Let monsters pick up Elf:$ loot
* | 9ca6e02 (HEAD, master) Distinct manual tiles
* | a16bb39 Restore trunk changelog entries removed by 673ecc60.
* | 1d9921b Touch the 0.13 changelog header with the tentative release date.
一旦你得到的東西你想要的狀態,把它推至到位桶你將最有可能需要git push --force origin master
。 請注意:這將強制將Bitbucket上的主設置爲您使用上述設置的任何設置。 另外:我們正在有效地重寫歷史。如果其他人對我們撤銷的合併提交進行了更改,我們將爲他們帶來問題。 (他們需要將他們的承諾重新分配到我們剛剛重新編寫的歷史記錄中。)
感謝您的幫助..我解決了 –
您能向我們展示您的歷史記錄嗎?類似於'git log -n 10 --oneline --graph'的輸出,可能帶有關於你想改變什麼的註釋? – Thanatos