Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I've just deleted one week of work! How to undo git rm -r --cached?

Tags:

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!


Edit:

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!

like image 785
Tyra Avatar asked Oct 03 '11 06:10

Tyra


People also ask

How do I undo a git delete?

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.

Does git rm -- cached delete the file?

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.

Can you undo git clean?

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.


1 Answers

(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]

  • vim e.g. optionally stores persistent undo,
  • eclipse IDE stores local history;

such features might save your a**

like image 76
sehe Avatar answered Jan 01 '23 19:01

sehe