---
title: "在 Git 中还原被删除的文件"
description: "在 Git 中还原被删除的文件"
canonical: https://oozou.com/til/restore-a-deleted-file-in-git-5
locale: zh-Hans
date: 2020-10-13
topic: shell
---

# 在 Git 中还原被删除的文件

> 在 Git 中还原被删除的文件

Published: 2020-10-13 · Topic: [shell](https://oozou.com/zh-Hans/til-topics/shell) ([markdown](https://oozou.com/zh-Hans/til-topics/shell.md))

```bash
# Find in which commit it's been deleted
$ git rev-list -n 1 HEAD -- <file_path>
4058ef780d2f6c4c6d57cfd7fd4ebe14c9dc28b3
# Restore it back
$ git checkout 4058ef780d2f6c4c6d57cfd7fd4ebe14c9dc28b3^ -- <file_path>
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/zh-Hans/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
