Search code examples
gitgit-stashgit-checkout

Design goes awry, after checkout to earlier commit on popping stash


My design (html/css) changed/gone awry after I popped back stashed repo.

Here is what I did. In order to temporary try out something,

  1. I did a git stash
  2. Then, checked onto an earlier commit git checkout fd3243d but did not make any changes.
  3. Immediately did git stash pop.

Now, to my horror (that sinking feeling), when I refreshed design in browser it went totally awry and on the very top it reads

<<<<<<< Updated upstream ======= >>>>>>> Stashed changes <<<<<<< Updated upstream ======= >>>>>>> Stashed changes

Can anybuddy help me get back to the state pre first step i.e. before I did a git stash?

I don't have any backup's and last commit was done quite a while back. I have a feeling that this can be done but don't know how since I am very new to git.

Can anybuddy help? Thanks dk


Solution

  • Assuming you were on the master branch before follow these steps:

    • Check that your stashed changes are still in the stash. Git won't pop (remove) a stash that could not be applied cleanly

      git stash list
      

      For more detailed checks try:

      git stash show stash@{<the-number-behind-your-stash>}
      
    • This should be the case (otherwise an edit to this answer will explain how to rescue your changes)

    • git reset --hard back to master (or any other branch that your stash was created from). You can find out from which branch (or commit) your stash was created by looking at the output from git stash list again

    • git stash pop should now apply your changes cleanly and your changes are back