git restore's Examples

Restore file from last commit (HEAD) to working directory

git restore main.py

Restore all modified files from last commit

git restore .

Restore file from a specific commit

git restore --source=abc123 index.html

Unstage file from staging area (keep local changes)

git restore --staged app.js

Reset file to last commit in index (unstage + reset content)

git restore --source=HEAD --staged app.js

Restore file to working directory only (same as default)

git restore --worktree README.md

Restore file to working directory only (same as default)

git restore --worktree README.md

Restore file in both staging area and working directory

git restore --staged --worktree config.yml

Restore file from previous commit (1 commit ago)

git restore --source=HEAD~1 config.json

Restore file from a specific branch

git restore -s develop app.py

Interactively restore selected hunks of a file

git restore --patch main.py

Restore file from commit or undo staged changes.

git restore file.txt

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us