How to Squash 3 commits into 1?

Kaycee picture Kaycee · May 29, 2017 · Viewed 22.4k times · Source

I'm fairly new to git, so I've been trying to figure out how to squash 3 commits into 1 so my PR can get merged. I've read a lot of docs and guides and sort of found out how to squash commits but one of my commits aren't showing up. I tried attaching a photo of my commits and a photo of my terminal when I type in: "git rebase -i HEAD~5", but unfortunately I'm a new user so I can't? But anyway, I would greatly appreciate some help.

Answer

danglingpointer picture danglingpointer · May 29, 2017

How to Squash 3 commits into 1?

  • do git log and confirm the commits you want to squash are commited, first.
  • if you want squash top 3 commits from your head,

Use this command,

git rebase -i HEAD~3

Here the tilde ~ symbol with 3 pick the top latest three commits and it will pop up in an interactive shell where you can select the top commit and squash other two commits into one by entering s, it means squash.

If your commit is not appearing then do git log and see, if not then

git add files
git commit -m 'your commit'