I have a brand new git repo. It has three commits.
I'd like to squash them together so my project history looks clean, and others don't see my hacky commits.
Obviously nobody else has seen the repo, as it's brand new, so changing history is not a problem. I am the only user.
However git rebase -i
wants me to track an upstream branch. I don't want to publish anything until I've tidied up the git log.
How can I do a interactive rebase, or squash commits in general, without tracking an upstream?
You can do this fairly easily without git rebase or git merge --squash . In this example, we'll squash the last 3 commits. Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash.
In case you are using the Tower Git client, using Interactive Rebase to squash some commits is very simple: just select the commits you want to combine, right-click any of them, and select the "Squash Revisions..." option from the contextual menu.
Git squash with a commit id The last command opens the interactive Git rebase tool which lists all of the commits in the branch. You must type the word pick next to the commit you want all others to be squashed into. Then type 'squash', or just the letter 's', next to each commit to squash.
You can skip tracking a remote branch by specifying the last n
commits you want to squash.
For eg. if you have 4 commits in your branch and you want to squash the last 3 commits effectively making a single commit, you can do git rebase -i HEAD~4
. You can then either fixup or squash the commits as you wish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With