DEV Community

Discussion on: Git: Are you an over-committer? Squash those commits!

Collapse
 
lucassperez profile image
Lucas Perez

Also, just to add a tiny info, instead of going HEAD~n to get the n last commits, you could pick the hash of the commit you want to go to.
Let's imagine that I have these 4 commits:

abc123    Last commit I made
def456    Yet another message
ghi789    Another message
jkl012    A commit message
Enter fullscreen mode Exit fullscreen mode

If I want to rebase the last 3 commits, I could pick the hash ghi789 and execute the rebase command like this:

git rebase -i ghi789^
Enter fullscreen mode Exit fullscreen mode

We have to put the ^, otherwise git will pick all the commits but the one indicated by the hash.
Alternatively, you could pick the hash of the commit that came immediately before the one I want, in this case, jkl012, so this would also work:

git rebase -i jkl012
Enter fullscreen mode Exit fullscreen mode

In the end it's all the same and we should do whatever we like and is used to, but I like knowing multiple ways of doing the same thing! 😅