> 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/25.-shi-yong-bian-ji-he-bing-fen-zhi.md).

# 25.使用变基合并分支

## 将分支恢复到合并之前

```powershell
git checkout lgnew

git hist
*   1ef2ec3 2023-05-05 | Merge branch 'master' into lgnew (HEAD -> lgnew) [aku]
|\
| * 1c78eab 2023-05-05 | Added teset3.txt (master) [aku]
* | 3d99c8f 2023-05-05 | Added teset2.txt [aku]
|/
* 31e5621 2023-05-05 | Added teset2.txt [aku]
* 5dc8b1e 2023-05-05 | Added .gitignore [aku]
* b77158a 2023-05-05 | Moved test.txt to lab [aku]
* 929f644 2023-05-05 | Added 123456 to the test.txt [aku]
* d7f681f 2023-05-05 | Added abc to the test.txt (tag: v1) [aku]
* 01b8702 2023-05-05 | Add first file (tag: v1-beta) [aku]

# 重置到合并前的最后一次提交
$ git reset --hard 3d99c8f
HEAD is now at a3f191c Added test3.txt
```

## 变基

```powershell
git rebase master
Successfully rebased and updated refs/heads/master.

git hist
* 2456c71 2023-05-05 | Added teset2.txt (HEAD -> lgnew) [aku]
* 31e5621 2023-05-05 | Added teset2.txt [aku]
* 5dc8b1e 2023-05-05 | Added .gitignore [aku]
* b77158a 2023-05-05 | Moved test.txt to lab [aku]
* 929f644 2023-05-05 | Added 123456 to the test.txt [aku]
* d7f681f 2023-05-05 | Added abc to the test.txt (tag: v1) [aku]
* 01b8702 2023-05-05 | Add first file (tag: v1-beta) [aku]
```

## 什么时候用变基

不用最好


---

# 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/25.-shi-yong-bian-ji-he-bing-fen-zhi.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.
