Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - undoing git rm [duplicate]

Tags:

git

git-rm

Possible Duplicate:
How to revert a “git rm -r .”?

Git SOS here. I worked 10 hours on a project without committing (I know, I know) and then I git added too many files, so I tried using git rm and accidentally deleted EVERYTHING. Is there hope for me? :(((

like image 606
user1436111 Avatar asked Dec 04 '12 08:12

user1436111


People also ask

Can you undo a git rm?

A reset will revert the current staging index and working directory back to the HEAD commit. This will undo a git rm . git checkout . A checkout will have the same effect and restore the latest version of a file from HEAD .

Does git rm delete file from history?

“git rm” command : the command to be executed on all branches, revisions and commits matching in the history, in this case it will remove the file from the repository and ignore files that don't match.


1 Answers

If you already commited changes, then:

git reset (--hard) HEAD~1 

If not then:

git reset git ls-files -d -z | xargs -0 git checkout -- 
like image 76
Hauleth Avatar answered Nov 03 '22 04:11

Hauleth