Undoing a git pull --rebase

GitGit RebaseGit PullGit StashGit Revert

Git Problem Overview


Hey I'm new to git and I need to undo a pull, can anyone help?!? So what I've done is...

  1. git commit
  2. git stash
  3. git pull --rebase
  4. git stash pop

this created a bunch of conflicts and went a bit wrong. Now doing 'git stash list' reveals that my stash is still there. Is it possible to revert my repo back to the point just after doing git commit. So effectively my repo only contains only changes I have made and nothing new from the server?

Git Solutions


Solution 1 - Git

Actually, to make this easier Git keeps a reference named ORIG_HEAD that points where you were before the rebase. So, it's as easy as:

git reset --hard ORIG_HEAD

Solution 2 - Git

using git reflog you will see a list of commits HEAD pointed to in the past

using

git checkout -b after-commit HEAD@{1} # or the commit you want to recover

you create a new branch at that precise position and check it out

Solution 3 - Git

You should checkout the command

git reset --merge

That eliminates the need for a git commit; git stash before a pull (Don't know about rebase though)

The command returns a workspace with uncommitted changes to the state before a conflicting pull.

Solution 4 - Git

Use git log -g and find the commit index you want to go back to, the just do git checkout index

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThomasView Question on Stackoverflow
Solution 1 - GitPat NotzView Answer on Stackoverflow
Solution 2 - GitknittlView Answer on Stackoverflow
Solution 3 - GitErik Martino HansenView Answer on Stackoverflow
Solution 4 - GitJohan DahlinView Answer on Stackoverflow