Undoing a git rebase

前端 未结 18 1589
孤城傲影
孤城傲影 2020-11-22 02:41

Does anybody know how to easily undo a git rebase?

The only way that comes to mind is to go at it manually:

  • git checkout the commit parent to both of t
18条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 03:02

    In case you had pushed your branch to remote repository (usually it's origin) and then you've done a succesfull rebase (without merge) (git rebase --abort gives "No rebase in progress") you can easily reset branch using command:

    git reset --hard origin/{branchName}

    Example:

    $ ~/work/projects/{ProjectName} $ git status
    On branch {branchName}
    Your branch is ahead of 'origin/{branchName}' by 135 commits.
      (use "git push" to publish your local commits)
    
    nothing to commit, working directory clean
    
    $ ~/work/projects/{ProjectName} $ git reset --hard origin/{branchName}
    HEAD is now at 6df5719 "Commit message".
    
    $ ~/work/projects/{ProjectName} $ git status
    On branch {branchName}
    Your branch is up-to-date with 'origin/{branchName}.
    
    nothing to commit, working directory clean
    

提交回复
热议问题