# Commit Manipulation and Reflog

### Commit Manipulation

In many projects, commits are more than a snapshot. It should represent a working state of the repository. That means, some projects don't really like it if you have a typo, then you have to create a separate commit to fix said typo.

So then, how do we rewrite the commit to fix the typo? That's where commit manipulation comes in.

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

{% hint style="warning" %}
Notice that the master branch changes to the new commit. That is, there will be no way to checkout the commit A unless you know the exact hash you are looking for.
{% endhint %}

Amending a commit adds some changes to an additional commit and "destructively" replaces the previous commit from it. This could be changes to the file, the author, or commit message, or even a combination of everything.

To do this is lazygit:

* Move your head to the commit to amend
* Make some changes and stage it
* Hit A to amend the current commit with the changes

### Reflog

That's pretty cool, but what if I screw up, and want to look at the commit before I amended it? There are no pointers or labels now pointing at my old commit? That's where reflog comes into play.

Reflog is essentially a history of all the commits your HEAD has touched. It also keeps track of the hashes so that you can easily navigate between commits that might have been lost otherwise.

To use reflog:

{% tabs %}
{% tab title="In lazygit" %}

* Click on the reflog tab
* Navigate the the commit you want, hit space to checkout
* You can also hit C to cherry pick the commit if you want to apply it to your current branch
  {% endtab %}

{% tab title="In Git CLI" %}

* Do `git reflog`.
* Find the hash of the commit you want to checkout
* `git checkout <hash>`
  {% endtab %}
  {% endtabs %}


---

# 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://wiki.nushackers.org/hackerschool/lightning-git/commit-manipulation-and-reflog.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.
