Git: “Cannot 'squash' without a previous commit” error while rebase

前端 未结 7 580
逝去的感伤
逝去的感伤 2021-01-29 21:06

I have the following in the to-do text of git rebase -i HEAD~2:

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

# Rebase 68         


        
7条回答
  •  孤独总比滥情好
    2021-01-29 21:49

    Interactive rebase presents commits in the reverse order of what you are used to when using git log. git rebase -i replays the selected commits in the exact (top-down) order they are listed in the saved rebase instructions file. When squashing, the commit selected for squashing is combined with the commit that precedes it in the (edited) list, i.e. the commit from the previous line. In your case - there is no previous commit for 56bcce7. You have to do one of the following

    • git rebase -i HEAD~3 (if you want to squash 56bcce7 into 684f917)
    • If you mean to combine 56bcce7 with e43ceba, and e43ceba doesn't depend on 56bcce7, then simply reorder them:

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

      UPDATE: Gus's answer below suggests a better way of doing the same, without reordering the two commits:

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

      This will squash/merge the two commits into one. When the interactive rebase asks for a reworded commit message for 56bcce7, provide the commit message that describes the union of 56bcce7 and e43ceba.

提交回复
热议问题