2

I have two commits locally:

commit adae40c5e2b69a41447b08cc3dcb77003611fbbe
Author: Me
Date:   Thu Mar 21 14:17:35 2019 +0000

    1.0.0

commit ceaa65ea06f48dc24554a6f798aae2d668f3a43d
Author: Me
Date:   Fri Feb 1 10:04:36 2019 +0000

    first commit

How do I squash these so there is only one commit with the message 1.0.0?

I tried the following but neither has worked for me:

git rebase -i HEAD~2
git rebase -i master
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
runnerpaul
  • 5,942
  • 8
  • 49
  • 118
  • Did you change the `pick` to `squash` for the second commit in the opening editor window? – kowsky Mar 21 '19 at 14:29
  • https://stackoverflow.com/search?q=%5Bgit-rebase%5D+first+commit – phd Mar 21 '19 at 14:51
  • 2
    In your specific situation, RomainValeri's answer is probably the simplest solution. However, it may be useful to understand why interactive rebasing isn't working for you, because rebase is a much more powerful / more general tool and will work in many cases where simply reset + commit will not – Mark Adelsberger Mar 21 '19 at 15:18

1 Answers1

8

For those not fond of interactive rebasing, in a situation like this it's also quite easy to just rewind and recommit :

git reset --soft HEAD~2
git commit -m "1.0.0"
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • 2
    Rebasing is an especially helpful feature in Git but it will not squash commits, it will do the opposite and preserve each commit. The `reset` then `commit` process you laid out is perfect for squashing the commit history. – benhorgen Mar 21 '19 at 14:38
  • 1
    @benhorgen You're right. It's unclear from my answer but I did refer to *interactive* rebasing (then choosing `squash` where it should) rather than "normal" rebasing. – Romain Valeri Mar 21 '19 at 14:43
  • @benhorgen - I'm not sure what you mean. A rebase can indeed squash commits. It is true that the original commits are preserved (at least temporarily) after any rebase, but the same is true of the rebase-and-recommit method. – Mark Adelsberger Mar 21 '19 at 15:16