Search code examples
gitversion-controlgit-pullgit-reset

Undo git pull, how to bring repos to old state (once again)


Please note, before indicating the question as a duplicate, that I have read the answer here but, with the solution proposed, I will delete all the uncommitted changes.

Problem:

I have developed new features using a dedicated branch. In the meanwhile, the master branch continued to be developed by others. I decided to do a git pull in order to rebase my code to the new one. However, there were conflicts: somebody has improved the code on the remote repo.

Question:

  1. I have some uncommitted changes on my local repo. How can I bring the repo to the old state with the old uncommitted changes?
  2. Did I already lose forever all the uncommitted changes?

Solution

  • If the rebase did start although you had local modifications, chances are you have the "autostash" option turned on.

    Otherwise, the rebase would not have started at all.

    Check the value of this config parameter :

    git config --get rebase.autostash
    

    You should see true


    You can run git rebase --abort to cancel the rebase.

    You should see a line :

    Applied autostash.
    

    which indicates that your unstaged changes have been restored.