1
git status

shows some files are deleted

deleted:    uploads/cus/zixk19hldk1.jpg
deleted:    uploads/cus/zixk19hldk1.jpg

Is there a way to recover those files

I tried git checkout . but thats not working

nithin k
  • 45
  • 1
  • 6
  • You snipped too much from the `git status` output but because of the behavior of `git checkout .` we can guess that this one thing you snipped out is that these are "changes to be committed". `git checkout -- .` or `git checkout .` (both mean the same thing) won't work because that copies from the *index*, which is precisely where these two files aren't. You need to `git checkout HEAD -- ` as in VonC's answer below; the `HEAD` commit contains these two files. These are "changes to be committed" *because* `HEAD` has the files and the index does not have them. – torek Feb 13 '20 at 16:58

1 Answers1

0

The recent command git restore is a new experimental command since Git 2.23.

git restore --source HEAD uploads/cus/zixk19hldk1.jpg
# shorter:
git restore -s @ uploads/cus/zixk19hldk1.jpg

You restore from HEAD (not from index).

With the old command:

git checkout HEAD -- uploads/cus/zixk19hldk1.jpg
git checkout @ -- uploads/cus/zixk19hldk1.jpg
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2.7? That sounds old ;) Any chance to upgrade to 2.25? If not: `git checkout @ -- uploads/cus/zixk19hldk1.jpg` – VonC Feb 13 '20 at 05:43