{"meta":{"title":"Rolling back changes made during a GitHub Copilot CLI session","intro":"Rewind your Copilot CLI session to a previous prompt to undo changes in conversation history, and optionally restore files.","product":"GitHub Copilot","breadcrumbs":[{"href":"/en/copilot","title":"GitHub Copilot"},{"href":"/en/copilot/how-tos","title":"How-tos"},{"href":"/en/copilot/how-tos/copilot-cli","title":"Copilot CLI"},{"href":"/en/copilot/how-tos/copilot-cli/use-copilot-cli","title":"Use Copilot CLI"},{"href":"/en/copilot/how-tos/copilot-cli/use-copilot-cli/roll-back-changes","title":"Roll back changes"}],"documentType":"article"},"body":"# Rolling back changes made during a GitHub Copilot CLI session\n\nRewind your Copilot CLI session to a previous prompt to undo changes in conversation history, and optionally restore files.\n\n## Introduction\n\nWhen you work in an interactive Copilot CLI session, Copilot can make changes to files, run shell commands, and modify your repository. If the result isn't what you expected, you can rewind to a previous point in the session to undo those changes.\n\nYou can trigger a rewind by pressing <kbd>Esc</kbd> twice when Copilot is idle, or by using the `/undo` slash command (or its alias `/rewind`).\n\nWhen you select a point to rewind to, you can choose whether to **Rewind the conversation only** or **Rewind the conversation and restore files**.\n\nRewind works in any directory, including folders that aren't Git repositories. It restores only the files that Copilot changed.\n\nThis article explains how to roll back changes. For more conceptual information about rewinding to an earlier point in a session, see [Canceling a GitHub Copilot CLI operation and rolling back changes](/en/copilot/concepts/agents/copilot-cli/cancel-and-roll-back).\n\n## Prerequisites\n\n* **A rewind point must exist.** You can't roll back before your first prompt in a session.\n* **File restoration is only available for sessions that tracked file changes.** If you resume a session that started before file-change tracking was enabled, only conversation rewind is offered. Start a new session to be able to restore file changes.\n* **File restoration skips files you changed yourself.** Files whose current contents no longer match what Copilot last wrote (for example, because you edited them afterward), and files that were too large to back up, are left untouched rather than overwritten.\n* **Rewind isn't available for remote-backed sessions**, or while the session still has work in progress.\n\n## Rolling back with a double Esc keypress\n\n> \\[!WARNING]\n>\n> * Rewinding cannot be undone. Once you roll back, later session history is permanently removed.\n> * If you choose to restore files, Copilot restores only the files it changed, and skips any file whose current contents no longer match what it last wrote, so your own later edits aren't overwritten.\n\nPressing <kbd>Esc</kbd> twice only opens the rewind picker when Copilot is idle. For details of what a double <kbd>Esc</kbd> does when an operation is in progress, see [Canceling a GitHub Copilot CLI operation and rolling back changes](/en/copilot/concepts/agents/copilot-cli/cancel-and-roll-back#what-pressing-esc-does-in-different-situations).\n\nWhen Copilot has finished responding to a prompt you've entered:\n\n1. Make sure the input area is empty and no work is in progress. If there's text in the input area, pressing <kbd>Esc</kbd> twice in quick succession clears the text instead of opening the picker.\n\n2. Press <kbd>Esc</kbd> twice in quick succession to open the rewind picker.\n\n   The picker lists available rewind points for the current session, with the most recent first. The ten most recent points are displayed at once. If there are more than ten, use the <kbd>↑</kbd> and <kbd>↓</kbd> arrow keys to scroll through them.\n   For each rewind point, the beginning of the prompt you entered is shown, along with how long ago you submitted it. For turns that changed files, the number of lines added and removed by that turn is also shown.\n\n3. Choose a rewind point and press <kbd>Enter</kbd>.\n\n   Choosing a rewind point opens an action menu where you can select **Conversation only** or **Conversation + files**. The latter is unavailable for a rewind point when neither that turn nor any later turn changed any files that can be restored. Before restoring, Copilot shows a per-file preview of the changes so you can confirm.\n\n   > \\[!NOTE]\n   > The rewind is applied relative to the state immediately **before** Copilot started working on the prompt, not immediately after it finished working on the prompt.\n\n   The prompt you selected is shown in the input area, so you can edit and resubmit it, if required.\n\n## Rolling back with the `/undo` slash command\n\nThe `/undo` slash command, and its alias `/rewind`, provide an alternative way of opening the rewind picker.\n\nBoth commands produce the same result that you get by pressing <kbd>Esc</kbd> twice when Copilot is idle and there is no text in the input area.\n\n## Verifying the rollback\n\nAfter rolling back, you can use Git commands to verify the state of your repository and confirm that it matches your expectations.\n\nTyping `!` allows you to run shell commands directly from the Copilot CLI input prompt, so you don't need to exit the CLI to check the repository state.\n\n| To do this                                                | Enter this command       |\n| --------------------------------------------------------- | ------------------------ |\n| Check which files show as modified, staged, or untracked. | `! git status`           |\n| Show the SHA and commit message of the current commit.    | `! git log --oneline -1` |\n| Review the unstaged changes.                              | `! git diff`             |\n\n## Further reading\n\n* [GitHub Copilot CLI command reference](/en/copilot/reference/copilot-cli-reference/cli-command-reference)"}