Zachary
Zachary

Reputation: 1703

How to get patch files from multiple commits?

For example, let's focus on the latest 4 successive commits. commit1 is the latest while commit4 the earliest:

commit1 HEAD
commit2
commit3
commit4
...

I want get patch file from commit1&2&3. I have tried the following two commands, but they generates different patch files:

git diff commit4 commit1 -- > file.patch
git format-patch -3 commit1 --stadout > file.patch

I want to know if the difference is crucial? Could I use any of them?

Upvotes: 1

Views: 535

Answers (2)

Simon
Simon

Reputation: 11

I want get patch file from commit1&2&3 ==> you may use git format-patch commit1..commit3 --stdout > file.patch

Upvotes: 0

Greg Hurrell
Greg Hurrell

Reputation: 5457

git diff only shows changes to the content, but git format-patch includes commit messages as well, making it more appropriate for most scenarios involving exchanging patches with other people (for example, so that you can share them using git send-email, or they can apply them via git am).

Upvotes: 1

Related Questions