I accidentally erase files. Fortunately, I have added those to index. Please tell me how to recover those files to working tree, without commiting.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With