Skip to content

Instantly share code, notes, and snippets.

@shellkore
Created January 18, 2019 17:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save shellkore/4ebec03a5893958aa00127d16b20baef to your computer and use it in GitHub Desktop.
Save shellkore/4ebec03a5893958aa00127d16b20baef to your computer and use it in GitHub Desktop.
squash your commits

SQUASH

Whenever you want to squash last commits in a single commit:-

first check your log

git log

CASE 1: your head is at the commit in which you want others to be squashed

count number of commits to be squashed. Let the number of commits be x

open rebase window using HEAD

git rebase -i HEAD~x

CASE 2: Your head is not at the commit which you want to squash

Note the SHA commit value of the oldest commit from where you have to start squashing

open rebase window using SHA value

git rebase -i <first 7 alphnumerics of SHA>

Follow the instruction and make the changes accordingly

TO SAVE

press esc key

type :x!

press return key

write your final commit message

press esc again

type :wq! or :x!

press return key

PUSH (if all these extra commits were pushed in GitHub repo also)

you have to push changes forcefully

git push -f origin master

replace 'origin' with your remote name and 'master' with your branch name.

Squash it up ;)

@pathakcodes
Copy link

Wahhh !!! We needed it .

@arkumish
Copy link

thank you @shellkore

@SJoshi7
Copy link

SJoshi7 commented Jan 18, 2019

Well written ! @shellkore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment