14

I had a lot of local changes.

I just accidentally did

git merge another_branch
git reset --hard HEAD^

on a lot of work. :( with the intention I didn't want the merged changes in here.

How do I recover the original state?

No, the local changes were never committed/stashed.

No way?

lprsd
  • 84,407
  • 47
  • 135
  • 168

6 Answers6

19

Foy anyone who is facing this problem in IDEs, there is a solution.

Search for the IDE editor history files of your IDE. I had a problem with Android Studio, so here I will give you a solution for Android Studio.

For example: In Android Studio you can always see the previous files by right clicking on the project folder → Local HistoryShow History.

You can see the change history of files and you can also open the files and compare it with new files side by side. If you need the old code, just copy paste it from there.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
12

If the changes had never been committed, stashed, or staged, then you're out of luck. If they have, then you should be able to get your changes back by looking for them in git reflog.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jamessan
  • 41,569
  • 8
  • 85
  • 85
1

Although the uncommitted modifications to tracked files will have been lost, I think any untracked files will still be around unless you subsequently deleted them.

Eric Walker
  • 7,063
  • 3
  • 35
  • 38
1

Try undoing on the file directly from the IDE. You'll get what you need.

It is probably not helpful for @Lakshman Prasad, but it will help someone else :-D

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
avrsanjay
  • 805
  • 7
  • 12
0

Look into the Recycle Bin!

I found my deleted (uncommitted) files there.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dan Alboteanu
  • 9,404
  • 1
  • 52
  • 40
0

I was able to recover my files, by using git log -g. My changes were there, because I committed them once, uncommitted my changes and then I saw all files on which I was working were lost.

By doing git log -g || git reflog -g it will display the recent commit logs.

I found my commit hash and I checked it out to that using this command: git reset #commitHashID

This may help someone with a similar scenario.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hanzla Habib
  • 3,457
  • 25
  • 25