How do you squash commits into one patch with git format-patch? How do you squash commits into one patch with git format-patch? git git

How do you squash commits into one patch with git format-patch?


I'd recommend doing this on a throwaway branch as follows. If your commits are in the "newlines" branch and you have switched back to your "master" branch already, this should do the trick:

[adam@mbp2600 example (master)]$ git checkout -b tmpsquashSwitched to a new branch "tmpsquash"[adam@mbp2600 example (tmpsquash)]$ git merge --squash newlinesUpdating 4d2de39..b6768b2Fast forwardSquash commit -- not updating HEAD test.txt |    2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)[adam@mbp2600 example (tmpsquash)]$ git commit -a -m "My squashed commits"[tmpsquash]: created 75b0a89: "My squashed commits" 1 files changed, 2 insertions(+), 0 deletions(-)[adam@mbp2600 example (tmpsquash)]$ git format-patch master0001-My-squashed-commits.patch


Just to add one more solution to the pot:If you use this instead:

git format-patch master --stdout > my_new_patch.diff

Then it will still be 8 patches... but they'll all be in a single patchfile and will apply as one with:

git am < my_new_patch.diff


I always use git diff so in your example, something like

git diff master > patch.txt