Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get deleted files back with git pull?

Tags:

git

backup

I had up to date repository. Then I had deleted several files and this was mistake. I would like to get fresh repository back. I do

$ git pull origin master

And expect to get everything from server, but getting message that everything is up to date.

How to get my sources from server using git pull then?

like image 657
vico Avatar asked Jun 25 '16 15:06

vico


People also ask

Can we recover deleted files from 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.

How do I restore a deleted GitHub file?

In the top right corner of GitHub.com, click your profile photo, then click Your organizations. Next to the organization, click Settings. In the left sidebar, click Deleted repositories. Next to the repository you want to restore, click Restore.


3 Answers

You can reset local branch to what's at remote

git reset --hard origin/main
like image 150
Jeff Puckett Avatar answered Oct 12 '22 16:10

Jeff Puckett


The files are in your local git history so you won't need to pull code to get them back. Run

git checkout <file>

on the missing files. If you don't have any uncommited changes then

git checkout .

in the git root directory will work as well.

like image 26
Harald Nordgren Avatar answered Oct 12 '22 16:10

Harald Nordgren


This shows all the deleted files.

git ls-files --deleted 

This will restore the deleted file.

git checkout <deleted file name with complete path>
like image 13
Manjunatha S M Avatar answered Oct 12 '22 17:10

Manjunatha S M