Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleted a file by mistake, how to get from origin master?

Tags:

git

I deleted a file on my desktop by mistake, how can I get it from the remote master?

like image 906
Blankman Avatar asked Jul 01 '10 20:07

Blankman


People also ask

How do I undelete a file in git?

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.

Can you recover a deleted branch git?

A deleted Git branch can be restored at any time, regardless of when it was deleted. Open your repo on the web and select the Branches view. Search for the exact branch name using the Search all branches box in the upper right. Click the link to Search for exact match in deleted branches.


1 Answers

git checkout -- /path/to/file

should be enough to restore it, since you have a local repo with that file in it.
That would restore your file at the version of the file present in the index.
(i.e. the last version you ran git add on it).

To restore it at the latest commit of your current branch:

git checkout HEAD -- /path/to/file
like image 54
VonC Avatar answered Sep 20 '22 12:09

VonC