Create a gist now

Instantly share code, notes, and snippets.

Squash last n commits
# Typically, a discussion between a repo owner and collaborator will result in a pull request being assigned back to
# the respective collaborator, a new commit created, and being assigned back to the repo owner for review. This interaction
# can result in many commits per pull request.
# If following the convention of a commit header message which prefixes with an issue number, squashing commits for the same
# issue is very easy.
# For example, if "git log" shows 3 commits with commit messages starting with "Issue #3" or "i3", it is easy to visually
# determine what "n" should be.
#git rebase -i HEAD-<n>
git rebase -i HEAD-3
# The above will place you in the editor. Find the latest (in time) commit for the issue. Change "pick" to "squash".
# This will squash all (earlier) commits into the one (latest) commit.
# When you attempt to execute "git push", it will fail because the tip of the remote branch does not match the local one.
# Perform the following ONLY on your feature branch within your remote forked repository since you are the only one
# modifying it.
git push --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment