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

前端 未结 8 1067
無奈伤痛
無奈伤痛 2020-11-30 16:58

I\'ve got eight commits on a branch that I\'d like to email to some people who aren\'t git enlightened, yet. So far, everything I do either gives me 8 patch files, or start

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 17:32

    Easiest way is to use git diff, and add in git log if you want the combined commit message that the squash method would output. For example, to create the patch between commit abcd and 1234:

    git diff abcd..1234 > patch.diff
    git log abcd..1234 > patchmsg.txt
    

    Then when applying the patch:

    git apply patch.diff
    git add -A
    git reset patch.diff patchmsg.txt
    git commit -F patchmsg.txt
    

    Don't forget the --binary argument to git diff when dealing with non-text files, e.g. images or videos.

提交回复
热议问题