Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Squash Commits in Git Desktop

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.

like image 372
Shwheelz Avatar asked Dec 28 '15 19:12

Shwheelz


2 Answers

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.`
like image 130
CodeWizard Avatar answered Oct 12 '22 13:10

CodeWizard


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

Starting with version 2.9 there is now a way to squash commits in GitHub Desktop.

Here are 2 of the convenient ways to do this.

  1. Select multiple commits in "History" tab (using Ctrl or Shift keys), right click on one of the selected commits and select "Squash 2 commits...".

enter image description here

  1. When merging a branch into another branch click on the arrow on the right to submit button and select "Squash and merge".

enter image description here

like image 35
wha7ever Avatar answered Oct 12 '22 13:10

wha7ever