WEEK 7 · LESSON 4 · TOPIC 4 OF 11 · Checking Out an Earlier Commit

Checking Out an Earlier Commit

Lesson progress

0% Complete

SECTION 1 OF 1

In this topic · 1 sections
  1. Overview

Overview

To inspect a previous project state, use:

git checkout <commit-id>

Git updates the working files to match that commit. The terminal reports a detached HEAD state because you are viewing a specific commit rather than working on the tip of a normal branch.

For example, if a later commit added a line to a file, checking out an earlier commit makes that line disappear from the working directory because the earlier saved state did not contain it.

Return to the latest state of the main branch with:

git checkout main

Before moving to an earlier commit, preserve pending work. Local changes that would be overwritten can prevent the checkout.