Old Versions of a File
Git restore --source.
You liked the home page better the way it was three commits ago. Git still has that version. You can bring back just that one file, without touching anything else.

- The old version was better
- Git still has it
- Bring back just one file
Bring back an old version
First, the history of the home page. We want the version from the welcome text commit, zero b a six zero four nine. Git restore, dash dash source, that hash, and the file name. Cat shows the file now has just two lines, like back then. Status shows it as modified, so we can commit it, if we're happy.
git log --oneline index.html f63a17a (HEAD -> main) Link to about page 0ba6049 Add welcome text f7d9757 Add home page git restore --source 0ba6049 index.html cat index.html <h1>My Site</h1> <p>Welcome!</p> git status --short M index.html
How it works
Dash dash source tells restore where to copy the file from. Any commit hash works. The file in your working folder is replaced with that old version. Nothing in your history changes. It's like copying the file out of an old snapshot.
| key | value |
|---|---|
| --source <hash> | where to copy from |
| <file> | which file |
| History | unchanged |
| Then | commit, if you like it |
Summary
git restore dash dash source copies a file out of any old commit. Next, visiting a whole old snapshot.
Key takeaways- git restore --source <hash> <file>
- Copies an old version
- Commit it if you like it