Reputation: 87077
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?
Upvotes: 15
Views: 28523
Reputation: 3703
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.
Upvotes: 0
Reputation: 805
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
Upvotes: 1
Reputation: 10232
Look into the Recycle Bin!
I found my deleted (uncommitted) files there.
Upvotes: 1
Reputation: 879
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 History → Show 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.
Upvotes: 23
Reputation: 42657
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
.
Upvotes: 12
Reputation: 7571
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.
Upvotes: 1