-1

How to get the deleted files back when...

  1. Files are rm ?
  2. Files are git rm ?
  3. Files are git rm and git commit ?
Sibevin Wang
  • 4,480
  • 3
  • 27
  • 27

1 Answers1

2

Files are rm

If you know which files are removed:

git check -- filename

or

git checkout-index filename

If you don't know which files are removed or there are too many removed files:

git ls-files -d | xargs git checkout --

Files are git rm

Use reset to roll back the index first

git reset HEAD

And use the commands listed above

git ls-files -d | xargs git checkout-index

Files are git rm and git commit

If you know which commit(ex: 2ae853) you remove the files, you can checkout files from the previous commit(2ae853^) of that commit:

git checkout 2ae853^ -- filename

If you forget which commit you removed the files, use rev-list to find the commit first:

git rev-list -n 1 HEAD -- filename

And use the previous command to get the files back.

Sibevin Wang
  • 4,480
  • 3
  • 27
  • 27