你如何使用git format-patch来压缩一个补丁? [英] How do you squash commits into one patch with git format-patch?

查看:408
本文介绍了你如何使用git format-patch来压缩一个补丁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个分支上有8个提交,我想通过电子邮件发送给一些不受git启发的人。到目前为止,我所做的每件事都会给我8个补丁文件,或者从开始的时候开始为分支历史记录中的每个提交提供补丁文件。我使用git rebase --interactive来压缩提交,但现在我尝试的所有内容都是从一开始就为我提供了无数的补丁。我做错了什么?

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 starts giving me patch files for every commit in the branch's history, since the beginning of time. I used git rebase --interactive to squash the commits, but now everything I try gives me zillions of patches from the beginning of time. What am I doing wrong?

git format-patch master HEAD # yields zillions of patches, even though there's 
                             # only one commit since master


推荐答案

我建议按如下方式在一次性分支上执行此操作。如果你的提交是在新行分支,并且你已经转回到你的主分支,这应该做的伎俩:

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 tmpsquash
Switched to a new branch "tmpsquash"

[adam@mbp2600 example (tmpsquash)]$ git merge --squash newlines
Updating 4d2de39..b6768b2
Fast forward
Squash 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 master
0001-My-squashed-commits.patch

希望这有助于!

这篇关于你如何使用git format-patch来压缩一个补丁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆