本文介绍了将我的所有提交(包括合并)压缩到一个提交中,而不更改历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在我的分支中有100次提交,我已经进行了3个星期的工作。偶尔地(每天,真的)我从原产地/主人拉并且合并到我的分支。

我怎么能(容易地)挤压我的所有提交入一个承诺没有搞砸历史?如果我将我的所有提交压缩成某种形式,当我的pull请求移动到origin / master时,我是否会销毁合并的origin / master pulls? 解决方案

压缩和保留历史在术语上大体上是直接相反的。

如果你的意思是你想做一个单独的提交你的变化,而不是来自上游主人的变化,你可能希望 rebase 到origin / master,然后从那里挤压。你可以从一次交互式rebase的调用中完成所有这些:

  git fetch origin 
git rebase -i origin / master

然后将所有行从 pick 压扁


Say I have 100 commits in my branch that I've been working on for 3 weeks. Occasionally (every day, really) I pull from origin/master and merge it into my branch.

How could I (easily) go about squashing all of my commits into one commit without messing up history? If I squash all of my commits into one somehow, would I destroy the merged origin/master pulls when my pull request gets moved into origin/master?

解决方案

"Squashing" and "preserving history" are approximately direct opposites in terminology.

If you mean that you want to make a single commit that includes only your changes and not the ones from upstream master, you would probably want to rebase onto origin/master and then squash from there. You could do all of this from a single invocation of interactive rebase:

git fetch origin
git rebase -i origin/master

and then change all of the lines after the first from pick to squash.

这篇关于将我的所有提交(包括合并)压缩到一个提交中,而不更改历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:36