git交互式将壁球压缩到下一次提交 [英] git interactive rebase squash into next commit

查看:112
本文介绍了git交互式将壁球压缩到下一次提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中,我可以使用交互式资源库来重写历史记录,这很棒,因为在我的功能分支中,我探索了不同的重构和完成方式,并使用部分工作的代码进行了大量提交.

In Git I can use an interactive rebase to re-write history, this is great because in my feature branch I made a ton of commits with partially working code as I explored different refactors and ways of getting it done.

在将分支重新合并或合并到master之前,我想将很多提交压缩在一起.

I'd like to squash a lot of the commits together before rebasing or merging the branch onto master.

一些编排的提交顺序是从第一(顶部)到底部(最后)

Some made up commits in order from first (top) to bottom (last)

1. Initial commit on feature branch "Automatic coffee maker UI"
2. Add hot chocolate as product
3. Add tea as product. Products are now generic
4. Create in memory data store for adapter tests
5. Cry because I can't get entity framework to create a composite key. Integration tests broken.
6. Implemented composite key!!
7. All tests green and feature done!

让我们说我想保留提交3、4和7.

Lets say I want to keep commits 3, 4 and 7.

使用我想压扁"提交的变基

Using rebase I want to "squash" commits

  • 1和2进入3.
  • 4个住宿
  • 5和6进入7

理想在交互式知识库中

1. squash
2. squash
3. pick (contains the work of 1 & 2)
4. pick 
5. squash
6. squash
7. pick (contains the work of 5 & 6)

但这是向后的,因为squash将一个提交与其先前的提交合并.我不知道如何使它向前挤压.

But that is backwards because squash merges a commit with its previous commit. I can't figure out how to make it squash forward.

我很难吗?我应该接受那是行不通的吗(我宁愿让它工作),还是有办法做到这一点?

Am I being difficult, and should I accept that won't work (I'd rather get it working), or is there a way to accomplish this?

我正在使用此命令

git checkout My-feature-branch
git rebase master -i

然后,我正在编辑即将出现的提交列表,并尝试通过保存文件并编辑编辑器来完成它,这通常对我有用.

Then I'm editing the list of commits that come up, and trying to finish it by saving the file and editing the editor, which typically works for me.

推荐答案

如果可行,您也需要重新排列提交的顺序,以使要保留的提交早于要压扁的提交.

You either need to also reorder the commits so the to-be-kept commit comes before the to-be-squashed commits if this is feasible.

如果这不可行,因为您会遇到不想解决的冲突,那就解决吧

If this is not feasible, because you then would get conflicts you don't want to resolve, just make it

1. pick
2. squash
3. squash
4. pick 
5. pick
6. squash
7. squash

压缩完成后,您可以编辑提交消息,以包含您希望最终提交的消息.非常简单. :-)

When the squashes are done, you can edit the commit message to contain the message you like the final commits to have. Easy as pie. :-)

您甚至可以做到

1. pick
2. fixup
3. squash
4. pick 
5. pick
6. fixup
7. squash

然后,我认为应该只启动一次提交消息编辑器,就像使用fixup一样,只需在不启动编辑器的情况下获取以前的提交消息即可.

Then I think there should only once the commit message editor being fired up, as with fixup the previous commit message is simply taken without launching the editor.

在压扁时,提交消息编辑器触发时,您还会同时获得两条提交消息,分别是要压入的提交和要压扁的提交,因此,您可以简单地删除自己不提交的提交消息不想保留.

On squash when the commit message editor fires, you also get both commit messages, the one from the to-be-squashed-into and the to-be-squashed commit, so you then can simply delete the commit message you don't want to keep.

这篇关于git交互式将壁球压缩到下一次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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