GitHub revert or reset?

This question already has an answer here:

  • Undo a Git merge that hasn't been pushed yet 25 answers

  • 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.


    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 (ie where it was before the merge).

    链接地址: http://www.djcxy.com/p/16974.html

    上一篇: Bitbucket,不小心拉错了分支

    下一篇: GitHub恢复或重置?