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

前端 未结 8 1064
無奈伤痛
無奈伤痛 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:14

    This is an adaptation of Adam Alexander answer, in case your changes are in master branch. This do the following:

    • Creates a new throwaway branch "tmpsquash" from the point we want (look for the SHA key running "git --log" or with gitg. Select the commit you want to be tmpsquash head, the commits that are after that in master will be the squashed commits).
    • Merges the changes from master to tmpsquash.
    • Commits the squashed changes to tmpsquash.
    • Creates the patch with the squashed commits.
    • Goes back to master branch

    laura@rune:~/example (master)$ git branch tmpsquash ba3c498878054e25afc5e22e207d62eb40ff1f38
    laura@rune:~/example (master)$ git checkout tmpsquash
    Switched to branch 'tmpsquash'
    laura@rune:~/example (tmpsquash)$ git merge --squash master
    Updating ba3c498..40386b8
    Fast-forward
    Squash commit -- not updating HEAD
    
    [snip, changed files]
    
    11 files changed, 212 insertions(+), 59 deletions(-)
    laura@rune:~/example  (tmpsquash)$ git commit -a -m "My squashed commits"
    [test2 6127e5c] My squashed commits
    11 files changed, 212 insertions(+), 59 deletions(-)
    laura@rune:~/example  (tmpsquash)$ git format-patch master
    0001-My-squashed-commits.patch
    laura@rune:~/example  (tmpsquash)$ git checkout master
    Switched to branch 'master'
    laura@rune:~/example  (master)$
    

提交回复
热议问题