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

前端 未结 7 682
逝去的感伤
逝去的感伤 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:56

    I had a similar problem which I solved as follows:

    This is the commit group I wanted to squash:

    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
    

    As you can see, I wanted no. 4, but 1, 2 and 3 had no previous commit to squash into. Hence the Cannot 'squash' without a previous commit error.

    My solution was to use the r option for # r, reword = use commit, but edit the commit message

    So my commits list looked like this:

    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
    

    After saving, the interactive shell asked me for the rewording of the chosen commit.

    After that, my commit log resulted in a single commit which resulted in a cleaner commit history.

提交回复
热议问题