-1

I am working on Git and did lots of changes to a particular file. By mistake, while committing I ran git stash and all changes made to that file are gone now. Is there any way to bring those changes back?? I used git stash show and git stash apply but it's not working.

phd
  • 82,685
  • 13
  • 120
  • 165
Ash28
  • 85
  • 1
  • 1
  • 11
  • 3
    `git stash list` should show you all stash changes. `git stash pop` will apply the top change to working directory. – Rishikesh Darandale Dec 17 '19 at 10:37
  • refer this link https://www.git-tower.com/learn/git/faq/restore-repo-to-previous-revision – AllwiN Dec 17 '19 at 10:39
  • I am getting this when use got stash pop: error: Your local changes to the following files would be overwritten by merge: src/main/java/restAPIFramework/com/rest/service/Service.java Please commit your changes or stash them before you merge. Aborting The stash entry is kept in case you need it again. – Ash28 Dec 17 '19 at 11:28
  • Okay. You have more changes in that file. Either you can commit those changes `git add /path/to/file && git commit -m {message}` or you have discard those changes `git checkout -- /path/to/file`(check the changes using `git diff` before doing this one). Once you have completed prior steps, then you should be able to `git stash pop` – Rishikesh Darandale Dec 17 '19 at 12:22

1 Answers1

1

git stash pop can be used with here to get back your changes.

git stash apply --index

If the --index option is used, then tries to reinstate not only the working tree’s changes, but also the index’s ones. However, this can fail, when you have conflicts

Harsh Mishra
  • 1,975
  • 12
  • 15