Suggest an editImprove this articleRefine the answer for “What does git restore <file> do?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`git restore <file>`** undoes changes in the specified file in the working tree, returning it to the state of the last commit or the staging area. **Key point:** the command undoes uncommitted changes in a file and returns it to the last saved state, without affecting the commit history.Shown above the full answer for quick recall.Answer (EN)Image`git restore <file>` undoes changes in the specified file in the **working tree**, returning it to the state of the last commit or the staging area. --- ## What exactly the command does When you run: ```bash git restore file.txt ``` Git: - removes all uncommitted changes in the file - replaces the file with the version from the **staging area**, if the file had been added - if the file was not in the staging area, it takes the version from the **last commit** --- ## What `git restore <file>` does NOT do - it does not change the commit history - it does not affect other files - it does not work with commits --- ## When to use it - you need to undo local edits in a file - the file is changed, but there is no need to commit - you need to quickly return the file to its original state --- ## Important to remember All unsaved changes in the file will be lost. Before using it, make sure you do not need them. --- ## Key phrasing for an interview > `git restore <file>` undoes uncommitted changes in a file and returns it to the last saved state, without affecting the commit history.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.