GitHub revert or reset? [duplicate]

流过昼夜 提交于 2019-12-11 08:43:07

问题


As you can see in the picture, I was working in feature forum_kolo_3, I decided to finish that feature and merge it to develop (but did not pushed the changes to remote develop, so its just local changes) and than I realized it was a bad idea and now I want to remove this merge, like it never happened.

So similar situation as described in here:git revert not allowed due to a merge but no -m option was given

But Im not quite sure what to do now, reverse or reset? I want to undo the merge I just did.

I also found this How to revert Git repository to a previous commit?

git revert --no-commit 0766c053..HEAD

git commit

Which seems like a better idea...but I have no clue


回答1:


Just find the last commit of the develop branch before merge, and then reset your git history to that commit.

git reset --hard <pre_merge_last_commit_id>

You can use graphical tool like gitk or git log --oneline --decorate=full --graph to find the last commit of the develop branch.

Note: Make sure you don't reset to the last commit of the feature branch instead.




回答2:


git revert is useful when the changes you want to undo were already published. It basically reverts the changes operated by another commit (removes the added lines, adds the removed lines, changes in the other direction the changed lines).

It is similar with an "Undo" operation but it usually happens after other commits were already added to the branch and it creates new commit(s).

now I want to remove this merge, like it never happened.

Since you didn't publish your changes, the best solution is to use git reset --hard.

If you are on the develop branch and you last command was git merge feature/forum_kolo_3, by running git reset --hard HEAD^1. It moves the current branch (develop) to the first parent of the merge commit (i.e. where it was before the merge).



来源:https://stackoverflow.com/questions/44799555/github-revert-or-reset

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