1

I have local project for which i created remote github repo. I didn't often push my local changes to remote repo but sometimes doing it. Recently while i was working on local project i have deleted some files using

rm fileName

After deleting i want to restore them and easiest way i think about was retrieving deleted files from github repo I have only one master branch in my repo and i tried

git fetch 

And console prompt me that all files up to date after checking files which i need i didnt find them. After it i tried

git pull 

and also i got notification that all files up to date and files which i need didnt uploaded to my local repo. I thought that maybe those files which i need haven't in remote repo but after checking i found them there. What i am doing wrong ?? How i should retrieve nedeed files ??

  • Does `git status` show them as deleted? If so just do `git checkout master -- fileName`. This resets the file to how it was at last commit, no pulling needed as you have a local copy of the whole repo already. – 17slim Dec 31 '19 at 20:14
  • Does this answer your question? [git recover deleted file where no commit was made after the delete](https://stackoverflow.com/questions/11956710/git-recover-deleted-file-where-no-commit-was-made-after-the-delete) – 17slim Dec 31 '19 at 20:16
  • @17slim thank you man i found solution by provided link – Наглый Спамер Dec 31 '19 at 21:05
  • @17slim if you will write your message like answer i will flag it as right solution – Наглый Спамер Dec 31 '19 at 21:06

1 Answers1

1

Instead of playing with git checkout (too confusing) or git reset, the proper command (with a recent Git version 2.23+) would be to use git restore.

git restore... restore files.

In your case, you want the version which was in the index restored to your working tree (assuming your file was already tracked):

git restore -s@ -SW -- yourFile

It will restore the file from the last commit, and update both working tree and index, completely restoring the file.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283