Skip to content
victor felder edited this page Jan 21, 2016 · 1 revision

Let's say you did a PR to add a single book in a single commit, but due to formatting errors you added 5 more commits until the PR passes Travis. Obviously, merging your PR would add 6 commits for a single line of content, which is not acceptable.

"Merging" these commits into one single commit is known as "squashing commits".

Here's one way to do it:

  1. In your git repo, do git rebase -i HEAD~6 (because we would like to rebase 6 commits starting at the latest one, which is the current HEAD)
  2. It will open an editor. Each line starting with pick describes a commit. On the first line, you will see the first commit of this PR, this is the commit we would like to keep, so we will not modify this line. For all the following lines, replace pick with fixup.
  3. Close the editor. Git will start rewriting history.
  4. git push --force
Clone this wiki locally