> For the complete documentation index, see [llms.txt](https://johnoraw.gitbook.io/iac-version-control/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://johnoraw.gitbook.io/iac-version-control/github/the-basics/undoing-local-changes.md).

# Undoing Local Changes

## Undo before Staging

My starting point is to check the current status, both locally and in VSCode.

<figure><img src="/files/zLrcN24WF3DBGiHUoNJx" alt=""><figcaption></figcaption></figure>

Now I’m making a small change in jor.txt and saving but I have not staged or committed.

<figure><img src="/files/1Y2yq2k4lTuO6SC4k0hf" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/UHfmGaxerONNHWZjxP6h" alt=""><figcaption></figcaption></figure>

Imagine I have broken something, and I want to revert to the last committed version. If I use the command **git checkout&#x20;*****filename*** I can revert to the previous version. I could also use **git restore&#x20;*****filename***.

<figure><img src="/files/FwVSUdKXQsZ7qHV8bwND" alt=""><figcaption></figcaption></figure>

## Undo after Staging

I have changed the same file again and this time, I have staged the change.

<figure><img src="/files/Uvkghg3NsymiLfkwkZ2U" alt=""><figcaption></figcaption></figure>

You may notice, each time git tells me my options! In this case, I will restore the staged file.

<figure><img src="/files/Q6RjezfdRVxPVkkBLQ3J" alt=""><figcaption></figcaption></figure>

Now I can either remodify or restore from the last commit.

## Undo after Commit

This time I will stage and commit all using VSCode. I am using the message “Update at 14:46”.

<figure><img src="/files/RyZaO0H2zMIrEdDXZ5lX" alt=""><figcaption></figcaption></figure>

First, I need to identify the version I want. As you can see, my messages are very unhelpful, that is a lesson! I want to revert to a previous saved version.

<figure><img src="/files/YfvxmwdLkWT9N4bibbVH" alt=""><figcaption></figcaption></figure>

To go back to that version, I can also use git checkout hash with the hash of the version I want to restore.

<figure><img src="/files/VAUXJDDBsYveLkiiEIcK" alt=""><figcaption></figcaption></figure>

I can then commit this and push it to GitHub.

<figure><img src="/files/sabdBtxn5xE4BDekaOFq" alt=""><figcaption></figcaption></figure>

And finally, to check it really has updated....

<figure><img src="/files/QLjibsIeoCwY0YBTXMvy" alt=""><figcaption></figcaption></figure>


---

# 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://johnoraw.gitbook.io/iac-version-control/github/the-basics/undoing-local-changes.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.
