Git在没有冲突的情况下压缩所有提交分支 [英] Git squash all commits in branch without conflicting

查看:265
本文介绍了Git在没有冲突的情况下压缩所有提交分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们来说,一个常见的开发工作流程是签出分支 b ,对其进行一堆处理,然后将所有这些提交压缩为一个(仍然在然而,在 rebase -i 过程中将所有的提交时,在多个步骤中经常会发生冲突。

我基本上想要将分支更改为一个代表存储库状态的提交最后一次提交 b



我已经做了一些搜索,但我还没有找到究竟是什么我在找。我不想 merge --squash ,因为我们想在合并之前测试压扁的特性分支。

解决方案

如果你不需要提交信息,那么你可以做一个软重置。然后文件保持原样,当你提交时,这个提交将在你重置的提交之上。



要找到要重置为的提交:

  git merge-base HEAD BRANCH_YOU_BRANCHED_FROM 

然后

  git reset --soft COMMIT_HASH 

然后重新编写提交,或许:

  git commit -am'这是新重新创建的一个提交'


A common development workflow for us is to checkout branch b, commit a bunch to it, then squash all those commits into one (still on b).

However, during the rebase -i process to squash all the commits, there are frequently conflicts at multiple steps.

I essentially want to alter the branch into one commit that represents the state of the repository at the time of the final commit on b

I've done some searching but I haven't found exactly what I'm looking for. I don't want to merge --squash because we would like to test the squashed feature branch before merging.

解决方案

If you don't need the commit information, then you could just do a soft reset. Then files remain as they were and when you commit, this commit will be on top of the commit you did reset to.

To find the commit to reset to:

git merge-base HEAD BRANCH_YOU_BRANCHED_FROM

Then

git reset --soft COMMIT_HASH

Then re-craft the commit, perhaps:

git commit -am 'This is the new re-created one commit'

这篇关于Git在没有冲突的情况下压缩所有提交分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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