Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover files from index

Tags:

git

I accidentally erase files. Fortunately, I have added those to index. Please tell me how to recover those files to working tree, without commiting.

like image 855
okadahiroshi Avatar asked Mar 12 '12 11:03

okadahiroshi


People also ask

How do I restore index files?

2020, Git 2.23+: use the git restore command: You can specify the source (index), default is the index and destination (working tree). That will restore the working tree from the index.

How do I find a recovered file?

To Restore That Important Missing File or Folder: Type Restore files in the search box on the taskbar, and then select Restore your files with File History. Look for the file you need, then use the arrows to see all its versions. When you find the version you want, select Restore to save it in its original location.

How do I restore my music on Android?

You can get help from this if you made a backup prior to deletion. Open Backup app and tap restore. Select the location of your backup and click 'Next'. Choose all the audio files you want to restore and tap on the 'Restore' at the bottom.


1 Answers

2014: git checkout-index will restore deleted files. It will NOT change the content of existing files.
(unless, as commented, using the -f/--force option)

Charles mentions a simpler solution, which can also be used to restore the content of files which existing in the working copy to their last indexed state:

git checkout -- the_erased_file

But that can silently overwrite an existing file, so don't make mistake.
(git checkout-index, by default, won't overwrite)


2020, Git 2.23+: use the git restore command:

You can specify the source (index), default is the index and destination (working tree).

git restore -- aFile

That will restore the working tree from the index.

git restore 
like image 199
VonC Avatar answered Oct 22 '22 13:10

VonC