# 版本回退

## 查看版本

1\.

```bash
$ git log
```

查看以往版本

```bash
$ git log --pretty=online
```

查看最近的一个版本

```bash
$ git reflog
```

查看以往每一次命令

## 返回版本

```bash
$ git reset --hard HEAD^
```

返回上一个版本，工作区文件对应改变

```bash
$ git reset --hard 1094a # 版本号只需前几位，git 会自动匹配
```

返回指定版本号

## 小结

### 使用场景

* `HEAD`指向的版本就是当前版本，因此，Git允许我们在版本的历史之间穿梭，使用命令`git reset --hard commit_id`。
* 穿梭前，用`git log`可以查看提交历史，以便确定要回退到哪个版本。
* 要重返未来，用`git reflog`查看命令历史，以便确定要回到未来的哪个版本。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yyaozhibo.gitbook.io/qian-duan-xue-xi/git/ban-ben-hui-tui.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
