I commited a wrong file, so I wanted to clean it up, but accidentally I overwrote all my files in the directory with last files committed to git.
Help please!
What I did:
git add fileIdidnotwanttoadd git rm -r --cached . git reset --hard HEAD
result: All my fixes are gone! I fixed 3 very hard bugs and it's all gone!
Thank you all. I used most of your suggestions, still had to redo a few things, but all is restored now. No more perfectionism, I learned my lesson!
You can restore a deleted file from a Git repository using the git checkout command. If you do not know when a file was last deleted, you can use git rev-list to find the checksum of the commit in which that file was deleted. Then, you can check out that commit.
The git rm command removes a file from a Git repository. This command removes a file from your file system and then removes it from the list of files tracked by a Git repository. The –cached flag lets you delete a file from a Git repository without deleting it on your file system.
You cannot undo a git clean command. The git clean -n option acts as a tryout command. It only displays the untracked files but does not delete them. The git clean --force command deletes all untracked files and folders in your working directory.
(from: Recover from git reset --hard?)
You cannot get back uncommitted changes in general, so the real answer here would be: look at your backup. Perhaps your editor/IDE stores temp copies under /tmp or C:\TEMP and things like that.[1]
git reset HEAD@{1}
This will restore to the previous HEAD - in case you had something committed earlier
[1]
such features might save your a**
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With