2016-09-20 43 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