How to get back a file you overwrote
Where to look immediately after overwriting a file by mistake, in the order most likely to get it back without restoring anything you did not need to.
Overwriting a file — uploading a new version over an old one, saving an edit that should not have gone live, or extracting an archive into the wrong place — is one of the more common file mistakes, and also one of the more recoverable ones, provided you act before making further changes on top of it.
Stop and check before doing anything else
The most useful first step is also the easiest: stop. Do not upload again, do not try to recreate the file from memory, and do not delete anything else in the same folder while you work out what happened. Every extra change makes it slightly harder to be sure exactly what state things were in before the mistake.
Check whether your account has automatic backups
Many hosting plans take automatic backups on a regular schedule, and the tool for accessing them is usually somewhere in your control panel's backup section. The genuinely useful feature here is being able to restore a single file rather than the entire account — look for an option to browse a backup's contents and pull out one item, rather than a full restore, which would also revert every other file to that point in time, including changes you want to keep.
Restoring the whole account rolls back everything to the backup's date, including work done since then on unrelated files. Unless you specifically need to undo more than the one mistake, restoring just the affected file avoids losing anything else in the process.
Check for a copy that already exists elsewhere
Before assuming the only copy was the one just overwritten, check the places a version might already exist:
- Your own computer. If you edited the file locally before uploading it, the previous version may still be sitting in a folder on your machine, or in your operating system's own recently-deleted items.
- A developer or agency you have worked with. Anyone who has worked on the site may have a local copy from their own last piece of work.
- Version control. If the site is deployed from a Git repository, the previous version is very likely still in its history and can be pulled back out even though the live copy has changed.
- A recycle or trash folder in your file manager. Some file managers keep a short-lived copy of anything replaced or deleted, separate from a full account backup.
If there is no backup and no other copy
This is the hardest case, and it is worth being honest about: if a file was genuinely only ever in one place and that place has now been overwritten with no backup, there is often no way to get the exact previous version back. Depending on the file, there may still be partial options:
- A cached version of a web page may still be viewable through a search engine's cache or a public web archive, which can at least let you see and retype the content even though the original file is gone.
- If the file was an image or document you sourced from somewhere else originally, the original source may still have its own copy.
- If part of the content still exists in a database — common with pages built through a content management system rather than a plain file — the file itself may be regenerable from that data even though the static file was lost.
Restoring the file once you have found a copy
Upload the recovered version back into its original folder using your FTP client or file manager, using the exact original file name and path so that anything on the site referencing it continues to work without changes elsewhere. Check the file's permissions after restoring it — 644 for a regular file — since a version pulled from an old backup or a different computer occasionally arrives with different permissions than the one it replaced.
Preventing this next time
Before editing or replacing any file that matters, particularly a configuration file or anything without an obvious second copy elsewhere, duplicate it first — see editing a file directly on the server for exactly this habit applied to in-place edits. It takes a few seconds and turns a mistake like this one into a non-event.
If you are not sure whether your hosting account takes automatic backups at all, or how far back they go, backing up your website covers what is available and how to set up your own schedule on top of anything included automatically, and our support team can confirm what backups currently exist for your specific account.
Related reading
One missing or broken file rarely needs a full restore — pull that single file out of the archive instead.
How to back up your websiteFiles and database, taken together, kept somewhere other than the account they protect — here are three ways to manage both.
How to delete files without breaking your siteThe habits that keep a clean-up from turning into an outage, and what to do before deleting anything you cannot immediately identify.
FTP, FTPS and SFTP: which to useThree protocols with confusingly similar names, one of which sends your password in the open. Here is what actually separates them.