git从合并中删除提交 [英] git remove commit from a merge

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

问题描述

我遇到以下问题...

I have the following problem...

我试图将一个远程分支合并到本地,然后将更改推送到存储库中……好吧,我获取了具有三个提交的远程分支,但是其中一个未完成,所以我不想将这些提交之一推送到存储库中...当我运行git log时,它显示了这个信息:

I was trying to merge a remote branch into my local, then push the changes to the repo... Ok, I fetched the remote branch which had three commits, but one of them is not finished, so I don't want push one of these commits to the repo... when I run git log, it shows me this:


commit: A1
merge: M1
    merge remote branch "remote/branch"

提交:A2
提交:A3
提交:A4

commit: A2 commit: A3 commit: A4

我想删除提交A2 ...我该怎么做?我正在搜索,有人说要使用git rebase或git reset,但是我不确定应该使用哪一个...以防万一,我没有推送这些更改

And I want remove commit A2... how can I do it? I was searching and some people says to use git rebase or git reset, but I'm not sure which one should I use... just in case, I hadn't pushed these changes

谢谢您的帮助

推荐答案

如果您尚未推送合并提交(这意味着A2尚未

If you haven't pushed your merge commit yet (that implies A2 was not pushed yet either) you can rebase interactively:

git rebase -i HEAD~3

现在删除合并提交行。然后,对提交进行重新排序,以使A2是最新的提交。完成后,分支:

Now delete the merge commit line. Then, reorder the commits so that A2 is the latest one done. Once that is complete, branch:

git branch incompleteFeature

然后将母版重置为上一次提交:

Then reset master to the previous commit:

git reset --hard HEAD^

现在您可以正确同步了,不完整的功能将位于它自己的分支中,直到您决定在以后准备好时将其合并。

Now you can sync up properly and the incomplete feature will sit in it's own branch until you decide to merge it in later when it's ready.

希望这会有所帮助

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

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