[英]how to generate one commit out of git diff
Is there a way to generate one commit
that contains the code changes between two branches? 有没有一种方法可以生成一个包含两个分支之间的代码更改的commit
? I have a branch and I committed too many times with short messages, and then I merged the latest state of master into it. 我有一个分支,并且用短消息提交了太多次,然后将master的最新状态合并到其中。 Now I want to put all the changes into one single commit with one single commit message and push to remote. 现在,我想用一条提交消息将所有更改放入一个提交中,并推送到远程。 It seems interactive rebase
will not work because I merged master into my branch at last ... 似乎交互式rebase
无法正常工作,因为我最后将master合并到了分支中...
When I do this: git diff master..mybranch
, I see the changes that I want to put into a new commit! 当我这样做时: git diff master..mybranch
,我看到了要放入新提交中的更改!
You should still be able to use interactive rebase, just start at master
and squash all the commits into a single one. 您仍然应该能够使用交互式rebase,只需从master
开始,然后将所有提交压缩为一个即可。
Alternatively, you can also use the output of that diff to generate a patch and then apply that patch using git apply
: 另外,您也可以使用diff的输出来生成补丁,然后使用git apply
来应用该补丁:
git diff master..mybranch > patch
git checkout master
git apply patch
Afterwards, add your changes and commit them as a single commit. 然后,添加您的更改并将其作为单个提交提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.