Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 Deleted folder can I recover with git?

OK. I was deleting precompiled assets in my public/assets folder. I accidentally deleted an entire folder I had in there as well. I checked out a repository and started webrick and the files seem to be loading, although when I look in the directory they aren't there? how do i restore/move those files back into the public/assets directory?

like image 721
ctilley79 Avatar asked Nov 08 '11 19:11

ctilley79


People also ask

How do I restore a folder in git?

You can restore files or folder with git restore. Here, master~1 reverts your folder to "1" revision back from your master branch. You use HEAD too. for example: git restore --source=HEAD~2 "Path_To_Restore" .

Can Git recover deleted files?

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.

How do you undo a delete in git?

Even better, in cases like committing a file deletion and then wanting to revert it, Tower's awesome undo feature lets you get the file back by simply pressing CMD-Z!

How do I restore a file in Git?

Git provides ways to recover a deleted file at any point in this life cycle of changes. If you have not staged the deletion yet, simply run `git restore <filename>` and the file will be restored from the index.


1 Answers

If you haven't commited the deletion. Check the changes that are pending with git status and use git checkout to restore a file to its last commited state ( HEAD ):

git checkout -- file_path

Git works on files not on directories.

like image 85
Felipe Cypriano Avatar answered Oct 13 '22 09:10

Felipe Cypriano