34 lines
909 B
Markdown
34 lines
909 B
Markdown
---
|
|
title: how to recover deleted file with git
|
|
seo_description: "short git tutorial on how to recover deleted files with git"
|
|
date: 2023-09-12T09:30:17+02:00
|
|
draft: false
|
|
snippet_types:
|
|
- git
|
|
---
|
|
|
|
I'd like to build a new nest.js command based off a file I deleted last week.
|
|
Here is how I go about getting that old file back via `git restore`
|
|
|
|
Step 1, find the file:
|
|
|
|
```shell
|
|
$ git log --name-only
|
|
/command
|
|
fd8bc2a6 Merge branch 'XXX-1111-remove-search-queue' into 'main'
|
|
fd07ddc3 XXX-1111: Remove search queue
|
|
apps/cli/src/cli.module.ts
|
|
apps/cli/src/db/backfill-search-queue.command.ts
|
|
apps/cli/src/db/db.module.ts
|
|
...
|
|
```
|
|
|
|
Step 2, restore the file:
|
|
|
|
```shell
|
|
$ git restore --source fd07ddc3~1 apps/cli/src/db/backfill-search-queue.command.ts
|
|
```
|
|
|
|
Note the `~1`. The file in question was deleted in commit fd07ddc3, so to
|
|
restore it we need to go one commit before it was deleted. `~1` does exactly
|
|
that.
|