> For the complete documentation index, see [llms.txt](https://alanmpan.gitbook.io/git-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alanmpan.gitbook.io/git-learning/git/12.-che-xiao-xiu-gai-ben-di-yi-bao-cun-zhuang-tai.md).

# 12.撤销修改-本地已保存状态

本节将学习如何恢复暂存前的更改，也就是在工作区下已经修改保存，还未暂存的文件。

每次操作前，我们都需要知道我们所在的分支，使用 `git status` 查看状态。目前我们还没有接触分支，你只需要知道你需要时刻关注这个状态。如果不在主分支上，使用 `git checkout master`切换到主分支。

## 修改文件

在 test 文件中添加一行 123，并保存。

```powershell
# 查看文件内容
$ cat .\test.txt
abc
123
```

## 恢复本地修改

现在我们尝试恢复操作，未暂存的文件恢复命令使用的是 `checkout` 命令，使用 `git checkout test.txt` 既可完成操作

```powershell
# 恢复
$ git checkout test.txt
Updated 1 path from the index

$ cat .\test.txt
abc
```
