Git & GitHub Interview Question #53
What does git restore do?
Undo & Recovery, Tags, Forks, Pull Requests & Code Review Mid-Level Intermediate
Quick Interview Answer
git restore is designed to restore file content in the working tree or staging area. It separates file-restoration tasks from the older multi-purpose git checkout command.
Detailed Explanation
git restore is designed to restore file content in the working tree or staging area. It separates file-restoration tasks from the older multi-purpose git checkout command.
For example, it can discard an unstaged modification by restoring a file from the index, or unstage a file with --staged while normally preserving its working-tree content.
Code Example
# Discard unstaged changes in one file
git restore Program.cs
# Unstage a file
git restore --staged Program.cs