> 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/23.-che-xiao-he-bing-wei-wan-shan.md).

# 23.撤销合并（未完善）

先跳过本节

## 恢复已提交的合并

### 使用 revert

此方法会创建新的 commit 来抵消对应的 merge 操作。再次合并时，文件无法合并，会提示 Already up-to-date. Git 误以为撤销的分支，所有内容我们都不需要了。

我们上个实验，将 lgnew 分支合并到了 master ，为了演示冲突，我们需要撤销合并。合并操作分为两步。

1. 找到合并的哈希值。使用 git hist 查看；
2. 确定撤销合并提交中的父提交编号
3. 使用 `git revert` 命令撤销合并。

```powershell
# 找到合并分支的提交哈希值
git hist --all
*   8588c0b 2023-05-05 | Merge branch 'lgnew' [aku]
|\
| * ead2515 2023-05-05 | Added teset2.txt (HEAD -> lgnew) [aku]
* | da0a6f8 2023-05-05 | Added teset3.txt [aku]
|/

# 查看提交详细信息
commit 8588c0b75af1f1a1cb29cb95d874631a39d30ef8
Merge: da0a6f8 ead2515
Author: aku <aku@example.com>
Date:   Fri May 5 13:39:39 2023 -0700

    Merge branch 'lgnew'

# 恢复
git revert -m 1 8588c0b
[master 32c5d64] Revert "Merge branch 'lgnew'"
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 lab/test2.txt
```

使用 `git revert` 命令来撤销先前的合并提交时，需要指定要撤销的父提交。`-m` 选项用于指定要撤销的合并提交中的父提交编号。`1` 是 `-m` 选项后面的参数，表示要使用的父提交编号。

合并提交的哈希值是 `8588c0b`，这个合并提交包含了两个父提交 `Merge: da0a6f8 ead2515`

* `ead2515 2023-05-05 | Added teset2.txt (HEAD -> lgnew) [aku]`
* `da0a6f8 2023-05-05 | Added teset3.txt [aku]`

通过 `-m` 选项指定的父提交序号，可以告诉 Git 要撤销哪个父提交。使用 `-m 1` 表示要撤销的父提交是序号为 `1` 的父提交，即父提交 `da0a6f8`。

***

此方法会创建新的 commit 来抵消对应的 merge 操作。再次合并时，文件无法合并，会提示 Already up-to-date. Git 误以为这个分支的东西都是不想要的。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://alanmpan.gitbook.io/git-learning/git/23.-che-xiao-he-bing-wei-wan-shan.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
