git从历史记录中删除合并提交 [英] git remove merge commit from history

查看:527
本文介绍了git从历史记录中删除合并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Git历史记录如下所示:

My Git history looks like that :

我想把紫色的承诺压制成一个单一的承诺。我不想在我的提交日志中再次看到它们。

I would like to squash the purple commits into a single one. I don't want to see them ever again in my commit log.

我试着做一个 git rebase -i 1 code>,但即使 1 在蓝色分支上(cf. picture),我仍然可以看到我的紫色分支上的每个提交。

I've tried to do a git rebase -i 1, but even though 1 is on the blue branch (cf. picture), I still see every commit on my purple branch.

如何完全删除紫色分支(从提交日志中)?

How can I completely remove the purple branch (from commit log) ?

推荐答案

code> git rebase -i > 这将允许您删除合并提交,并且日志将成为您想要的一行。您也可以删除不再需要的任何提交。你的基金会不起作用的原因是你没有回头路。

Do git rebase -i <sha before the branches diverged> this will allow you to remove the merge commit and the log will be one single line as you wanted. You can also delete any commits that you do not want any more. The reason that your rebase wasn't working was that you weren't going back far enough.

警告:
您正在重写历史记录。对已经推送到远程回购的更改进行此操作会导致问题。我建议只在本地进行提交。

WARNING: You are rewriting history doing this. Doing this with changes that have been pushed to a remote repo will cause issues. I recommend only doing this with commits that are local.

这篇关于git从历史记录中删除合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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