git remove commit from a merge

醉酒当歌 提交于 2019-12-10 22:55:07

问题


I have the following problem...

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"

commit: A2 commit: A3 commit: A4

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

Thanks for the help


回答1:


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

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.

hope this helps



来源:https://stackoverflow.com/questions/5395793/git-remove-commit-from-a-merge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!