2

I want to squash my 3 last commit together (from ax38aa to ax18aa).

i had

commit ax18aa
commit ax28aa
commit ax38aa
commit ax48aa
commit ax58aa

Code

git rebase -i ax48aa

but was surprised that when i did git log i have only

commit ax48aa
commit ax58aa

and didn't ask mi the new message for the commit. How can i do? please? who can help please Thank youu,

9
  • Does this answer your question? Squash my last X commits together using Git
    – mnestorov
    Commented Aug 21, 2020 at 14:05
  • @mnestorov no . I did git rebase -i ax48aa
    – Jappa
    Commented Aug 21, 2020 at 14:07
  • Does the same result happen when you do git rebase -i HEAD~3
    – mnestorov
    Commented Aug 21, 2020 at 14:08
  • but now in my git log i haven't the commit ax18aa commit ax28aa commit ax38aa so can't see :/.
    – Jappa
    Commented Aug 21, 2020 at 14:10
  • @mnestorov can you help me please?``
    – Jappa
    Commented Aug 21, 2020 at 14:12

2 Answers 2

3

That can be done like this:

git reset --soft ax38aa
git commit --amend -m "some blahblah"
3
  • thank you @eftshift() but i don't want to squash the ax58aa the new commit i mean for the squashed commit commit ax18aa, commit ax28aa, commit ax38aa
    – Jappa
    Commented Aug 21, 2020 at 14:01
  • 2
    git reset --soft ax38aa
    – phd
    Commented Aug 21, 2020 at 14:29
  • 1
    You also need to add -m before the "some blahblah"
    – Ben Waters
    Commented Feb 8, 2022 at 21:33
0

It looks like you squashed all of the commits during your interactive rebase, leaving you in a state of rebasing. This means that you are currently doing the rebase, but have not finished it and can only see the oldest two commits ax48aa and ax58aa. The easiest way to get out of this situation is to:

git rebase --abort

This will discard any changes you might have done and will put you in the state before the rebase. If by any chance you still do not see all of your 5 commits, then look into the reflog with git reflog, find the first commit and do git reset --hard ax18aa.

Now do a new rebase again, but this time, pick the oldest/top most commit of your interactive rebase.

git rebase -i HEAD~3
# or
git rebase -i ax48aa

and then do the following:

pick ax38aa commit message 3
squash ax28aa commit message 2
squash ax18aa commit message 1

This will do what you wanted.

Also keep in mind that after your rebase, you will have a new commit and you will need to force push to your remote repo in order for your changes to be uploaded!

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.