I was working on a file then deleted it by mistake before commiting. I restored it but I don't see any changes, was restored to the initial version. Is there a way to see what I was working on?
Asked
Active
Viewed 266 times
0
-
1Via GIT - no. You can do it via IDE maybe. Jetbtains tools support Local History feature. Also check your basket ) – Ilya Mokin Jun 24 '21 at 12:17
-
@IlyaMokin what about git fsck? Maybe it can help? – ToughCookie Jun 24 '21 at 12:19
-
Was your file commited in previous commit? – Muhammad Zahab Jun 24 '21 at 12:49
-
@ToughCookie `git fsck` only operates on objects in its own database, not files in the working directory. – chepner Jun 24 '21 at 12:49
-
@MuhammadZahabAhmadKhan yes, it was, not a new file – ToughCookie Jun 24 '21 at 13:09
-
@ToughCookie with `git fsck` we can restore `commits` which were fully lost from history, have no parent commits and even deleted from `reflog`. But unfortunately, we can not restore changes which were not committed at all – Ilya Mokin Jun 28 '21 at 17:47
2 Answers
0
Depends on your IDE. If you are using Jetbrains look for Local History in the File menu and see if it has stored those changes.
Edit - To avoid this in future consider using one of the two following plugins:
https://marketplace.visualstudio.com/items?itemName=micnil.vscode-checkpoints
https://marketplace.visualstudio.com/items?itemName=xyz.local-history
Be aware that this can cause VS Code to get confused, please see the following answer for more details: How to see local history changes in Visual Studio Code?

Zach Tait
- 160
- 8
-
-
Right click on the project item or folder and click Local History to display the history I believe – Zach Tait Jun 24 '21 at 12:39
-
0
I deleted a file but didn’t commit
$ git checkout HEAD "filename"
I deleted a file and committed the deletion
$ git reset --hard HEAD~1
I committed the deletion and then I did more commits
$ git log -- <filename>
$ git checkout <commit hash> -- <filename>
$ git checkout <deletion commit hash>~1 -- <filename>
I deleted a file, committed and pushed
$ git revert --no-commit <commit>
Here is the reference.

Muhammad Zahab
- 1,049
- 10
- 21
-
I deleted a file but didn’t commit $ git checkout HEAD "filename" I need to restore non commited changes. – ToughCookie Jun 24 '21 at 13:15
-
https://stackoverflow.com/questions/7147680/accidentally-reverted-to-master-lost-uncommitted-changes – Muhammad Zahab Jun 24 '21 at 13:18