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,

Jappa
  • 101
  • 8
  • Does this answer your question? [Squash my last X commits together using Git](https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git) – mnestorov Aug 21 '20 at 14:05
  • @mnestorov no . I did **git rebase -i ax48aa** – Jappa Aug 21 '20 at 14:07
  • Does the same result happen when you do `git rebase -i HEAD~3` – mnestorov Aug 21 '20 at 14:08
  • but now in my git log i haven't the **commit ax18aa commit ax28aa commit ax38aa** so can't see :/. – Jappa Aug 21 '20 at 14:10
  • @mnestorov can you help me please?`` – Jappa Aug 21 '20 at 14:12
  • @mnestorov in this link https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git they said that **git rebase -i ** – Jappa Aug 21 '20 at 14:16
  • During your interactive rebase, to each commit, what was the command you issued? Did you pick some of the commits? Did you squash all of them? – mnestorov Aug 21 '20 at 14:18
  • i changed all the pick to squash. @mnestorov – Jappa Aug 21 '20 at 14:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220217/discussion-between-mnestorov-and-jappa). – mnestorov Aug 21 '20 at 14:20

2 Answers2

3

That can be done like this:

git reset --soft ax38aa
git commit --amend -m "some blahblah"
eftshift0
  • 26,375
  • 3
  • 36
  • 60
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!

mnestorov
  • 4,116
  • 2
  • 14
  • 24