2016-09-20 42 views
23

git rebase -i HEAD~2待完成文字我有以下幾點:混帳:「不是‘南瓜’之前沒有能提交」錯誤而變基

pick 56bcce7 Closes #2774 
pick e43ceba Lint.py: Replace deprecated link 

# Rebase 684f917..e43ceba onto 684f917 (2 command(s)) 
# 
# Commands: 
# p, pick = use commit 
# r, reword = use commit, but edit the commit message 
# e, edit = use commit, but stop for amending 
# s, squash = use commit, but meld into previous commit 
# f, fixup = like "squash", but discard this commit's log message 
# x, exec = run command (the rest of the line) using shell 
# d, drop = remove commit 
# 
# These lines can be re-ordered; they are executed from top to bottom. 
# 
# If you remove a line here THAT COMMIT WILL BE LOST. 
# 
# However, if you remove everything, the rebase will be aborted. 
# 
# Note that empty commits are commented out 

現在,當我嘗試壓扁第一個(56bcce7 )和前第一加「S」挑第二個,我得到以下錯誤:

Cannot 'squash' without a previous commit

有人能解釋我這是什麼意思?我該怎麼辦呢?

我想壓扁第一次提交(56bcce7)和「選擇並改寫」第二(e43ceba)提交

+1

如果你真的想擠壓,把HEAD〜2改成HEAD〜3。 – ElpieKay

+0

並且可能使用--root,如果HEAD〜2是您的第一次提交:https://stackoverflow.com/a/598788/2444812 – wirap

+0

要刪除絨毛,您只需要粘貼示例的前4行。 – wirap

回答

28

互動變基禮物犯的你是用來使用git log時什麼順序相反。 git rebase -i以確切(自上而下)的順序重播所選提交,它們在保存的rebase指令文件中列出。當壓扁時,選擇壓扁的提交與(編輯)列表中提交的提交相結合,即來自前一行的提交。在你的情況 - 以前沒有提交56bcce7。你必須做以下

  • git rebase -i HEAD~3一個(如果你想擠進56bcce7684f917
  • 如果你的意思是結合56bcce7e43ceba,而e43ceba不依賴於56bcce7,後來乾脆重新排序其中:

    r e43ceba Lint.py: Replace deprecated link 
    s 56bcce7 Closes #2774 
    

    UPDATE:下面Gus's answer建議做同樣的一個更好的辦法,而不重新排序兩個提交:

    r 56bcce7 Closes #2774 
    s e43ceba Lint.py: Replace deprecated link 
    

    這將壓縮/合併兩個提交到一個。當交互式底座要求爲56bcce7重新提交提交消息時,請提供描述聯合的提交消息56bcce7e43ceba

+0

我想把'56bcce7'擠壓成'e43ceba'。那麼,我該如何做第一步呢? – Dawny33

+0

@ Dawny33查看更新的答案 – Leon

13

我有一個類似的問題,我解決如下:

這是提交組我想壁球:

1 s 01cc5a08 Removes open div 
2 s a2b6eecf Restores old fonts 
3 s 603479ff Cleans left out div 
4 pick 5afdbc33 Update: show logo on landing page 
5 s 04c1cb13 change version of dev and prod from 1 to 2 
6 s bbe6a8f8 Update: show logo on landing page if they have one 
7 s c0d6008a Adds check for C users 

正如你所看到的,我想沒有。 4,但是1,2和3沒有以前承諾壓扁成。因此,不能'擠壓'沒有以前的承諾錯誤。

我的解決辦法是使用r選項# r, reword = use commit, but edit the commit message

所以我提交列表是這樣的:

1 r 01cc5a08 Removes open div 
2 s a2b6eecf Restores old fonts 
3 s 603479ff Cleans left out div 
4 s 5afdbc33 Update: show logo on landing page 
5 s 04c1cb13 change version of dev and prod from 1 to 2 
6 s bbe6a8f8 Update: show logo on landing page if they have one 
7 s c0d6008a Adds check for C users 

保存後,交互的shell問我要的選擇提交措詞。

之後,我的提交日誌導致了一次提交,導致更清晰的提交歷史記錄。

0

剛纔我也已經遇到過這個問題,那只是粗心大意。你可以解決下一個問題:當你試圖擠壓第一個(56bcce7)並選擇第二個時,你應該先添加「s」第二行,但不是第一行。你也可以參考下一個網站:http://backlogtool.com/git-guide/en/stepup/stepup7_5.html

+0

嗨!如果您結帳[如何創建一個最小化,完整和可驗證的示例](http://stackoverflow.com/help/mcve),以便將來在堆棧溢出時進行嘗試,那將會更好。 -謝謝 – Momin