Reputation: 531
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!
Upvotes: 21
Views: 14834
Reputation: 1124
I did not find any of the above solutions successful. Running
git status
in the root you will see all the uncommitted changes. To discard those changes caused by the
git -rm --cached <files>
you would want to use
git checkout -- *
I hope this helps alleviate your stress.
Upvotes: 0
Reputation: 392911
(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**
Upvotes: 14
Reputation: 1323883
git reflog
.git rev-list
)Upvotes: 7
Reputation: 467131
There are various situations in which you may be able to recover your files:
git add <file>
when <file>
contained the content you want to get back) then it should be possible to (somewhat laboriously) get that file back by following this method.git stash
while working on those files, they are recoverable either via git stash list
, or methods 1. or 2. above.Otherwise, I'm afraid you may be out of luck. :(
Upvotes: 7