> For the complete documentation index, see [llms.txt](https://gittutorial.gitbook.io/practical-git-via-gitextensions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gittutorial.gitbook.io/practical-git-via-gitextensions/rewrite-history.md).

# Rewriting History

Changing the published commits is a bad practice as it will mess the history of other developers. Usually they will see both our old and new commits hence confused. Their old branches on top of the old commits will need to rebase on top of the new commits too.

However, rewriting history is the key to clean up our own branch that has not been published. We can amend commits, reword commits, squash commits and even get rid of one of them.

Tips: although you can get back your commits using `reflog`, creating a backup branch before rebasing can help you get back your original branch/commits in case anything wrong during rebase. Moreover, you can easily compare your rebased commits with the original ones. BTW, when creating the backup branch, you can untick the `Checkout after create` so as to stay on the original branch.


---

# 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://gittutorial.gitbook.io/practical-git-via-gitextensions/rewrite-history.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.
