Squash Commits in Git Desktop

Shwheelz picture Shwheelz · Dec 28, 2015 · Viewed 13.3k times · Source

I'm trying to squash 6 commits into a single commit using a branch that I already pushed to GitHub.

I tried to do this via command line, but I keep receiving no-op instead of the commits for that branch.

Is there a way to do this via GitHub desktop that might make more sense?

Please provide step by step if possible;

I'm new to using GitHub for collaborative purposes and my knowledge doesn't span very far past git add, commit, and push.

Answer

CodeWizard picture CodeWizard · Dec 28, 2015

In order to do a git squash follow those steps:

// X is the number of commits you wish to squash, in your case 6
git rebase -i HEAD~X

Once you squash your commits - choose the s for squash = it will combine all the commits into a single commit.

enter image description here


You also have the --root flag in case you need it

try: git rebase -i --root

--root

Rebase all commits reachable from <branch>, instead of limiting them with
an <upstream>.

This allows you to rebase the root commit(s) on a branch.  
When used with --onto, it will skip changes already contained in `<newbase>`   
(instead of `<upstream>`) whereas without --onto it will operate on every 
change. When used together with both --onto and --preserve-merges, all root 
commits will be rewritten to have `<newbase>` as parent instead.`