Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sleepdefic1t/67e53bc58dac45a8b637aa7418674cdb to your computer and use it in GitHub Desktop.
Save sleepdefic1t/67e53bc58dac45a8b637aa7418674cdb to your computer and use it in GitHub Desktop.
GIT: Squash, merge and apply patch

Squash and create patch

If your commits are in the "newlines" branch and you have switched back to your "master" branch already, this should do the trick:

git checkout -b tmpsquash
git merge --squash newlines
git commit -a -m "My squashed commits"
git format-patch master

Apply the patch

Note: You can first preview what your patch will do:

First the stats:

git apply --stat a_file.patch

Then a dry run to detect errors:

git apply --check a_file.patch

Finally, you can use git am to apply your patch: it allows you to sign off an applied patch. This can be useful for later reference.

git am --signoff < a_file.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment