How to revert a file to an earlier version
The fastest way to undo changes depends on when you made them and what operating system you use. If you changed a file moments ago, Ctrl+Z (Windows and Linux) or Command+Z (Mac) will undo the last action inside most programs. If you closed the file or the program crashed, you will need to look for a backup or use your system's file recovery tools.
Most operating systems keep older versions of files automatically, but where they store them and how to reach them differs. Windows uses File History and System Restore. Mac uses Time Machine. Linux does not have a built-in system-wide recovery tool, but many file managers and text editors store backups on their own. Cloud services like Google Drive, OneDrive, and Dropbox also keep version histories you can browse and restore from.
The method that works for you depends on whether the file is local (stored only on your computer), synced to the cloud, or part of a version control system like Git. Each has a different recovery path.
Key Takeaways
- Use Ctrl+Z or Command+Z to undo changes while a file is still open in the program you edited it in.
- Windows File History and Mac Time Machine can restore older versions of files if you closed the program without saving or need to go back further than undo allows.
- Cloud services like Google Drive, OneDrive, and Dropbox show a version history you can view and restore from without needing system backups.
- If you use Git or another version control system, you can revert to any previous commit using command-line tools or a graphical interface.
- Some text editors and design programs store automatic backups in a hidden folder, which you can find in the program's preferences or settings.
Undo changes while the file is still open
The simplest way to revert changes is to undo them before you close the file. Press Ctrl+Z on Windows or Linux, or Command+Z on Mac. Each press undoes one action in reverse order — if you typed a sentence, deleted a word, then changed the font, pressing undo three times will undo all three in reverse.
Most programs show an undo history if you hold down the undo button or look in the Edit menu. In Microsoft Word, click the arrow next to the undo button (curved arrow pointing left) to see a list of recent actions. In Google Docs, open File and select Version history to see when changes were made and by whom. In Adobe Photoshop, open the History panel to see every action you took and click on any earlier state to jump back to it.
If you cannot remember what you changed or how many times you pressed a key, undo all the way back to when you opened the file. Most programs will not let you undo past the point where you opened the document, so you will not accidentally erase the file itself.
Restore a file using Windows File History
If you closed the file without saving or your program crashed, Windows File History can restore an older version. File History must be turned on first — it does not work by default. Open Settings, go to System, then select Backup. Turn on Backup with File History and choose which folders to back up. Windows will then save copies of your files every hour.
Once File History is running, right-click the file you want to restore and select Restore previous versions. A window will open showing every backup Windows has of that file, with dates and times. Click the version you want and select Restore. Windows will replace the current file with that older version.
If the file is in a folder that is not being backed up, you can add it. In the Backup settings, click More options, then select Backup these folders. Add the folder that contains the file you need to recover. File History will start backing up that folder on the next scheduled backup, which is usually within an hour.
Restore a file using Mac Time Machine
Mac Time Machine works similarly to Windows File History but must be set up before you need it. Connect an external hard drive to your Mac, open System Settings, click General, then select Time Machine. Turn on Time Machine and select the external drive as your backup disk. Time Machine will then save hourly backups of your entire Mac.
To restore an older version of a file, open Finder and navigate to the folder containing the file. Click the Time Machine icon in the menu bar (clock icon) and select Enter Time Machine. A timeline appears on the right side of the screen showing when backups were made. Click an earlier date to see what the folder looked like at that time. Find the file you want, select it, and click Restore. Mac will copy that version back to the current location.
If you do not have an external drive, you can use iCloud Drive to sync files and access version history through iCloud.com. Open iCloud.com in a web browser, click Files, find the file, right-click it, and select Version History to see older copies.
Restore files from cloud storage version history
If your file is stored in Google Drive, OneDrive, Dropbox, or iCloud Drive, you can view and restore older versions without needing a local backup. These services keep version histories automatically, usually for 30 days or longer.
In Google Drive, right-click the file and select Version history. A panel opens showing every version with timestamps. Click a version to preview it, then click Restore this version to replace the current file. In OneDrive, right-click the file, select Version history, and click a previous version to restore it. In Dropbox, right-click the file, select Version history, and click Restore next to the version you want. In iCloud Drive, right-click the file on iCloud.com and select Version History.
Cloud version histories are separate from your computer's backups, so they work even if your local backup system is not set up. However, once you delete a file from the cloud, the version history usually disappears after 30 to 180 days depending on the service. If you think you might need an old version later, download it to your computer or keep it in a separate folder.
Revert changes in Git and version control systems
If you use Git or another version control system, you can revert to any previous commit. Open a terminal or command prompt and navigate to the folder containing the file. Type git log to see a list of all commits with dates and messages. Find the commit you want to go back to and copy its commit hash (the long string of letters and numbers).
To restore the file to that commit, type git checkout [commit-hash] -- [filename], replacing [commit-hash] with the hash you copied and [filename] with the name of the file. Git will restore that file to the state it was in at that commit. If you want to undo the most recent commit entirely, type git revert HEAD, which creates a new commit that undoes the previous one.
If you use a graphical Git tool like GitHub Desktop, Sourcetree, or GitKraken, you can see the commit history visually. Right-click a commit and select Revert or Restore to go back to that version. These tools are easier to use if you are not comfortable with command-line tools.
Find automatic backups in program settings
Many programs create automatic backups without you having to set them up. Microsoft Office saves recovery files in a hidden folder. If Word or Excel crashes, open the program and look for a Document Recovery pane that appears automatically. If it does not appear, go to File, then Options, then Trust Center, then Trust Center Settings, then Autorecover File Location. The folder shown there contains backup copies.
In LibreOffice (the free alternative to Microsoft Office), go to Tools, then Options, then Load/Save, then General. Check the box for Always create a backup copy. LibreOffice will then save a backup with a .bak extension every time you save. These backups are stored in the same folder as the original file.
Text editors like VS Code, Sublime Text, and Notepad++ also store backups. In VS Code, go to File, then Preferences, then Settings, and search for backup. Enable the backup setting and choose where to store backups. In Sublime Text, go to Preferences, then Settings, and search for backup_dir to set a backup location.
Frequently Asked Questions
Can I undo changes after I saved the file?
Yes, but only if you have a backup or version history. Undo (Ctrl+Z or Command+Z) only works while the file is open in the program. Once you close the file, undo is no longer available. You will need to use File History, Time Machine, cloud version history, or Git to restore an older version.
How far back can I restore a file?
It depends on your backup system. Windows File History and Mac Time Machine keep hourly backups as long as your backup drive has space, which can be months or years. Cloud services usually keep versions for 30 to 180 days. Git keeps every commit forever unless you delete the repository. If you do not have any backup system set up, you cannot restore a file once it is closed and changed.
What if I cannot find the file in my backups?
Check whether the file was being backed up. Windows File History and Mac Time Machine only back up files in certain folders by default. If your file was in a folder that was not included, it will not be in the backup. You can add that folder to your backup settings going forward, but past versions will not be recoverable. For cloud files, check the trash or recycle bin — deleted files often stay there for 30 days before permanent removal.
Does reverting a file delete my current changes?
Yes. When you restore an older version, the current version is replaced. Before you restore, save a copy of the current file with a different name if you think you might need it later. Some programs and cloud services will keep the old version in a version history, but it is safer to save it yourself.
Can I restore just part of a file, not the whole thing?
Not automatically. You will need to restore the full older version, then manually copy the parts you want to keep from the current version and paste them back in. Some programs like Google Docs show changes side-by-side so you can see what changed and decide whether to keep it. In Git, you can restore individual lines or sections using git diff and git apply, but this requires command-line knowledge.