> ## Documentation Index
> Fetch the complete documentation index at: https://aysdog-mintlify-5d426013.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Revert recent commits safely with commitdog revert

> Pick from your last five commits and create a revert commit that undoes the selected change, then push — without rewriting history.

`commitdog revert` lets you undo a recent commit safely. Rather than rewriting history, it creates a new revert commit that reverses the changes from the commit you select. You pick from the five most recent commits in an interactive list, confirm, and commitdog handles the rest — including prompting you to push afterward. If a revert is already in progress (due to conflicts from a previous run), commitdog detects it and lets you continue or abort.

## Usage

```bash theme={null}
commitdog revert
```

## Revert flow

<Steps>
  <Step title="Stash unstaged changes (if needed)">
    If your working tree has local modifications, commitdog offers to stash them before reverting so the operation starts from a clean state:

    ```text theme={null}
      you have unstaged changes. stash them first? [Y/n] ›
    ```

    The stash is popped automatically after the revert completes.
  </Step>

  <Step title="Pick a commit to revert">
    commitdog lists the five most recent commits with their short hash, subject, and relative date:

    ```text theme={null}
      recent commits:

      1  a3f9c12  feat(auth): add refreshToken and verifyToken  (2 hours ago)
      2  bb01e44  fix: resolve session timeout on logout         (yesterday)
      3  c190d87  chore: update dependencies                     (3 days ago)
      4  d45a001  docs: add API reference                        (4 days ago)
      5  e88b3f2  feat: initial project setup                    (5 days ago)

      [1-5] pick, [e] enter hash, [q] quit ›
    ```

    Enter a number to select that commit, `e` to type a commit hash manually (7–40 hex characters), or `q` to abort.
  </Step>

  <Step title="Confirm the revert">
    commitdog shows which commit you are about to revert and asks for confirmation:

    ```text theme={null}
      reverting a3f9c12 — feat(auth): add refreshToken and verifyToken
      ⚠  this creates a new revert commit. continue? [Y/n] ›
    ```

    Press Enter or `y` to proceed.
  </Step>

  <Step title="Revert commit is created">
    commitdog runs the revert and confirms:

    ```text theme={null}
      ✓ reverted a3f9c12
    ```

    It then asks whether to push the revert commit:

    ```text theme={null}
      push to origin/main? [Y/n] ›
    ```
  </Step>
</Steps>

## Merge commit handling

If you select a merge commit, commitdog asks which parent to revert to:

```text theme={null}
  ⚠  this is a merge commit. which side do you want to revert to?

  1  main  (before the merge — undo it entirely)
  2  feat/auth  (the branch that was merged in)

  [1/2] pick ›
```

Pick `1` to undo the merge entirely (the most common choice) or `2` to revert to the state of the branch that was merged in.

## Conflict handling

If the revert produces conflicts, commitdog exits with instructions:

```text theme={null}
  ✗ revert has conflicts — resolve them manually:

    1. fix the conflicting files
    2. git add .
    3. git revert --continue

  or to cancel: git revert --abort
```

The next time you run `commitdog revert` while a revert is in progress, commitdog detects the state and offers to continue or abort:

```text theme={null}
  a revert is already in progress.

  [c] continue  [a] abort  [q] quit ›
```
