我正在研究一個有master分支的git倉庫,我們將其稱爲ab
分支。我的團隊正在致力於ab
分支機構,並使用github提供了拉請求工作流程。我的一個隊友向他的分支jeremy_ab_deletions
提出了要求,要求ab
分支。我正在檢查/測試他的更改,但是當我將它們合併到ab
分支中時,我意外地將它們合併到了master中,並在我發現錯誤之前將master推送到了github。想我可以只是混合恢復我做的變化git revert SHA
,它似乎工作...搞砸了主git分支......無法弄清楚我需要恢復
我認爲這已經足夠,我高興地切換回我的AB分支,並繼續工作。然而,現在我意識到前面提交的ab
分支應該是從來沒有落在主人,都在掌握之中。這是......非常混亂。由於他的分支最初是從ab
分裂出來的,然後我將它合併成了主人,所以我應該使用git revert -m 1 SHA
將它歸還。
今天我想弄清楚我究竟在哪裏出了問題,而且我根據git歷史和我的引用日誌來了解各種困惑。首先,我試圖恢復的就返回,然後做git revert -m 1 SHA
但是git的告訴我:
fatal: Mainline was specified but commit 4c431c345dfe0a856967c090932c32f153824085 is not a merge.
所以我覺得OK了...也許這不是合併提交,我需要針對不同的SHA。但看歷史我不能爲我的生活出其中哪一個是合併提交...
This was supposed to be on AB...
…
d985b5bcf8 Browse code
Nathan B authored 8 days ago
This was supposed to be on AB...
…
0e01911273 Browse code
Nathan B authored 8 days ago
removed unecessary tests
4c431c345d Browse code
Nathan B authored 8 days ago
Apr 17, 2012
removing un-used views and pages
a546f90ed3 Browse code
jeremychurch authored 10 days ago
是說「這應該是對AB」的兩次提交是恢復提交以恢復「已刪除的不必要的測試」和「刪除未使用的視圖和頁面」提交。下一次承諾是在今天,而在此之前的承諾是在16日,這兩者都沒有關係。我沒有看到實際的合併發生在哪裏。
我經歷了我的reflog,看看到底發生了什麼事。我使用git reset --hard [email protected]{NUM}
去上下了reflog版本,然後檢查關鍵文件,看看那個地方是否有不好的變化。最後,我把範圍縮小到這些reflogs:
1fe2be2 [email protected]{79}: checkout: moving from 1fe2be29c6eda9f9fc9eb0b372ee83b7c15dfc2c to jeremy_ab_deletions
1fe2be2 [email protected]{80}: [email protected]{3}: updating HEAD
4c431c3 [email protected]{81}: [email protected]{1}: updating HEAD
47a97af [email protected]{82}: commit: removed unecessary tests, routes, and controller actions
4c431c3 [email protected]{83}: merge jeremy_ab_deletions: Fast-forward
1fe2be2 [email protected]{84}: checkout: moving from master to ab
d985b5b [email protected]{85}: revert: This was supposed to be on AB...
0e01911 [email protected]{86}: revert: This was supposed to be on AB...
4c431c3 [email protected]{87}: merge jeremy_ab_deletions: Fast-forward
c121a08 [email protected]{88}: checkout: moving from jeremy_ab_deletions to master
4c431c3 [email protected]{89}: commit: removed unecessary tests
a546f90 [email protected]{90}: checkout: moving from ab_page_changes to jeremy_ab_deletions
511b340 [email protected]{91}: checkout: moving from jeremy_ab_deletions to ab_page_changes
a546f90 [email protected]{92}: pull [email protected]:REDACTED/repo.git ab-remove-stuff: Fast-forward
具體HEAD @ {} 88這裏沒有壞的提交,HEAD @ {} 87呢。因此,我認爲我搞砸了merge jeremy_ab_deletions: Fast-forward
提交是合理的......但我無法弄清楚那會是「合併提交」。我試過這個:
$ git revert -m 1 4c431c3
fatal: Mainline was specified but commit 4c431c345dfe0a856967c090932c32f153824085 is not a merge.
我...找不到實際的合併提交它似乎?有沒有人知道我做錯了什麼:/我現在都失去了。
如果有人*拉壞了壞主人,會有什麼影響?我可以在那裏做第一步(完全消除這種情況的歷史),然後他們可以拉和接收正確的主人?或者當上遊沒有意識到變化時,git會感到困惑? – nzifnab 2012-04-27 19:07:50
如果有其他人拉掉了不好的「主人」分支,他們將不得不經歷基本相同的步驟。如果他們自那時以來沒有對*他們的*副本進行任何更改,他們可以通過'取出固定主副本並更新他們的參考文獻來將其短路。很容易明白爲什麼如果你只記得每個克隆開始*就像*克隆它的「原始」:所以如果你必須在「原始」上執行步驟1,2,3,那麼你還必須在克隆上執行步驟1,2,3。 – torek 2012-04-27 19:29:36
要去第一步,並確保拉着主人的另一個人也得到了固定。哈哈,這會教我合併和隨意推! – nzifnab 2012-04-27 19:51:41