Skip to content

Instantly share code, notes, and snippets.

@izumskee
Last active March 29, 2023 18:35
Show Gist options
  • Save izumskee/23619a9c3df271d07c73fffcebf44b65 to your computer and use it in GitHub Desktop.
Save izumskee/23619a9c3df271d07c73fffcebf44b65 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