Reputation: 6004
I am learning git and trying out squashing. I'd like to squash all commits on the master and be left only with initial one. For example, my commit history looks like this:
2c825e339b60702b7b48c2ea022e473341d89a7d (HEAD -> master) another edit
f676a10db6a0cfe3cebb8f84aad971b481483181 second file
dc55b957a94bc4a3d6c1b6d8c134407aa4c8316c initial
After that I ran git rebase -i dc55b957a94bc4a3d6c1b6d8c134407aa4c8316c
The usual way described all over the net is to replace every pick
with squash
, but the first one. After doing that I am presented with this commit history:
2067070140c38f8ecf5f70894e6267bfee614d85 (HEAD -> master) second file
dc55b957a94bc4a3d6c1b6d8c134407aa4c8316c initial
How come the squash
didn't work all the way to the initial commit?
Moreover, if I run the same squash command again, there is only 1 pick statement
in the interactive window. Changing it to squash
triggers error and leaving it to pick
does nothing. I have found
git reset --soft HEAD~1
git commit -m "1.0.0"
to be an effective way of squashing only 2 commits. How exactly can I use the git rebase --squash
to achieve the same result?
Upvotes: 1
Views: 50
Reputation: 30212
You had to do git reset --soft HEAD~2
and then do git commit --amend -m 1.0.0
Upvotes: 1
Reputation: 79733
The commit you specify in the rebase command is the parent of the first commit you want to modify or move. This is difficult for the first commit of the repository as it doesn’t have any parents. Instead you can use the --root
option:
git rebase -i --root
This should give you all the commits.
Upvotes: 1