Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I squash commits without tracking a remote branch?

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?

like image 866
mikemaccana Avatar asked Nov 17 '14 11:11

mikemaccana


People also ask

How could you squash multiple commits without?

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.

How do you manually commit 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.

How do you squash some commits on a branch?

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.


1 Answers

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.

like image 126
gravetii Avatar answered Nov 16 '22 16:11

gravetii