Get back a file you wrote over by accident

When you save a new file with the same name as an old one, macOS overwrites the original — but the old version isn't always gone. Your best recovery option depends on whether you have a backup and how long ago the replacement happened. If you act quickly, you can often undo the save directly in the application. If that doesn't work, Time Machine (if you've been using it) can restore the earlier version. If neither of those works, third-party recovery software can sometimes retrieve the overwritten file from your disk, though success depends on how much new data has been written since.

The key is speed. The longer you wait and the more you use your Mac after the replacement, the harder recovery becomes. Start with the fastest option — undo in the application — and work down the list only if that doesn't work.

Key Takeaways

  • The Undo command in most Mac applications will reverse a save if you haven't closed the file yet — try Command+Z immediately after you realize the mistake.
  • Time Machine can restore a previous version of a file if you've been backing up regularly, and you can browse snapshots by date without restoring your whole system.
  • The Versions feature in newer macOS applications (Pages, Numbers, Keynote, and some others) saves automatic snapshots you can browse and restore directly.
  • Third-party recovery tools like DiskWarrior or Data Rescue can sometimes retrieve overwritten files, but they work best when used soon after the replacement happens.
  • Prevention is simpler than recovery — use File > Duplicate before editing important files, or turn on automatic backups through Time Machine or iCloud.

Undo the save before you close the file

If you just replaced the file and haven't closed the application yet, Command+Z (the Undo command) will reverse the save in most programs. This works in Microsoft Word, Google Docs, Apple's Pages, and many others — but only if you undo before quitting the application or closing the document.

Press Command+Z repeatedly if you need to step back through multiple changes. Watch the title bar: if it shows a dot next to the filename, the document has unsaved changes, which means the undo worked. Once you've undone to the version you want, save it with a different name (File > Save As) so you don't overwrite it again.

This method fails if you've already closed the file or quit the application. Once the application closes, the undo history is gone and Command+Z won't help. This is why the first few seconds after you realize the mistake matter most.

Check the Versions history in the application

Newer Mac applications — including Pages, Numbers, Keynote, Preview, and some third-party programs — automatically save versions of your document as you work. You can browse these snapshots and restore an earlier one without using Time Machine.

Open the file and click File in the menu bar, then look for "Revert to" or "Browse All Versions". In Pages, Numbers, and Keynote, this option appears as "Browse All Versions". A timeline will open on the right side showing snapshots of the document at different times. Click the version you want and click "Restore" to replace the current file with that earlier snapshot.

This feature only works if the application supports it and if you haven't manually deleted the version history. Older applications like Microsoft Word don't use this system — they rely on Time Machine instead. Check your application's File menu to see if this option is available before moving to other recovery methods.

Restore from Time Machine

If you've been backing up to Time Machine, you can restore the file to the state it was in before you replaced it. Open Time Machine by clicking the Time Machine icon in the menu bar (top right of your screen) or by opening System Settings > General > Time Machine and clicking "Enter Time Machine".

Navigate to the folder where the file is located. You'll see a timeline on the right side showing when backups were made. Click the backup from before you replaced the file — usually the most recent one before the mistake. The file will appear in its earlier state. Click "Restore" to bring that version back to your Mac.

Time Machine only works if you've already set it up and have been running backups. If you haven't enabled Time Machine, this option won't help you now, but you should set it up immediately to protect against future accidents. Go to System Settings > General > Time Machine and click "Add Backup Disk" to choose an external drive.

Use recovery software if backups aren't available

If you don't have Time Machine backups and the application doesn't support Versions, third-party recovery software can sometimes retrieve the overwritten file. Programs like DiskWarrior, Data Rescue, and Disk Drill scan your hard drive for data that's been marked as deleted or overwritten but hasn't yet been physically erased from the disk.

Download and install the recovery software on your Mac or on another computer, then run a scan of the drive containing the replaced file. The software will show you files it can recover. Search for the filename you're looking for and select it for recovery. Save the recovered file to a different drive (not the same one you're scanning) to avoid overwriting it again.

Recovery software works best when used soon after the file is replaced, before the disk space is reused for new data. The longer you wait and the more you use your Mac, the less likely recovery becomes. These tools are not free, and recovery is not may provide — they work only if the old file data hasn't been completely overwritten yet.

Prevent this from happening again

The easiest solution is to avoid the problem in the first place. Before editing an important file, use File > Duplicate to create a copy with a different name. Edit the copy, and keep the original untouched. This way, even if you save over the copy by accident, the original is still there.

Set up Time Machine on an external drive so every change is backed up automatically. You don't have to think about it — just plug in the drive and let macOS handle the rest. For files you work on constantly, enable the Versions feature by making sure your application supports it and that you're saving to your Mac's local drive (not a network location).

If you use iCloud Drive, Google Drive, or Dropbox, these services also keep version history for a limited time. Check the application's settings to see how many previous versions are stored and how long they're kept.

Frequently Asked Questions

Can I undo a file replacement if I've already quit the application?

No. Once you close the application, the undo history is erased and Command+Z won't work. Your options then are Time Machine, Versions (if the application supports it), or recovery software. This is why acting quickly matters — if you realize the mistake while the file is still open, undo is your fastest fix.

Will Time Machine recover a file if I don't remember when I replaced it?

Yes. Open Time Machine and navigate to the folder where the file is. The timeline shows when each backup was made. Click through the backups from newest to oldest until you see the version you want, then restore it. You don't need to know the exact time — you just need to find the backup from before the replacement happened.

Does recovery software work on files stored in iCloud Drive?

Recovery software scans your local hard drive, not cloud storage. If the file is stored in iCloud Drive, check iCloud's version history first — most cloud services keep previous versions for 30 days. Open the file in iCloud.com or in the application and look for a version or history option. If that doesn't work, recovery software won't help because the file isn't stored locally on your Mac.

What if the recovery software finds the file but won't let me open it?

Recovered files are sometimes corrupted because the data was partially overwritten. Try opening it in a different application — for example, if a Word document won't open, try opening it in Pages or Google Docs. If the file is still unreadable, the overwritten data was too damaged to recover. This is another reason to act quickly: the sooner you recover, the less likely the data is corrupted.

Should I stop using my Mac after I replace a file I need back?

Yes, if you're planning to use recovery software. Every time you save a new file, download something, or install an update, new data is written to your disk and may overwrite the old file's data. If you've replaced an important file and don't have backups, shut down your Mac and use recovery software on another computer, or use an external drive to run the scan.