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

前端 未结 8 979
無奈伤痛
無奈伤痛 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.

    0 讨论(0)
  • 2020-11-30 17:34

    Based on Adam Alexander's answer:

    git checkout newlines
    ## must be rebased to master
    git checkout -b temporary
    # squash the commits
    git rebase -i master
    git format-patch master
    
    0 讨论(0)
提交回复
热议问题