Skip to content

Instantly share code, notes, and snippets.

@SrivastavaKshitij
Created September 15, 2022 14:47
Show Gist options
  • Save SrivastavaKshitij/dc6b82dac2a5599bf80a9850b0ca0b68 to your computer and use it in GitHub Desktop.
Save SrivastavaKshitij/dc6b82dac2a5599bf80a9850b0ca0b68 to your computer and use it in GitHub Desktop.
Squash multiple commits into one

let's suppose there are 4 commits on top of the latest master that we want to squash

commit 1
commit 2
commit 3
commit 4
origin/master, origin/HEAD, master
  1. rebase on master with SHA

git rebase -i [SHA]

  1. ^^ command will open up a text editor with every commit starting with the keyword pick apart from the top most commit, change every commit's pick to squash

close the editor

  1. ^^ this will open an text editor with commit messages from every commit. Either you can leave the file as is or remove every commit and type a single commit

  2. close the editor and you have successfully squashed all 4 commits

@SrivastavaKshitij
Copy link
Author

git reset --soft HEAD~1
git diff --staged > patch

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