Skip to content

Instantly share code, notes, and snippets.

@shubham7298
Forked from shellkore/squah.md
Created January 18, 2019 18:04
Show Gist options
  • Save shubham7298/6a552f698067b0726d57ec837cf96b15 to your computer and use it in GitHub Desktop.
Save shubham7298/6a552f698067b0726d57ec837cf96b15 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 ;)

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