Before executing this command, keep in mind that it will leave you in a detached head state.

Use git checkout <sha1> to check out a particular commit.

Where <sha1> is the commit unique number (SHA-1 hash value) that you can obtain with git log.

Here is what you could do after you are in the detached head state:

Copy the files or make the changes that you need to a folder outside your Git folder, check out the branch where you need them git checkout <existingBranch> and replace files.

Otherwise, you could do the following to get a copy of the project in the state that you want without getting into the detached head state:

Create a new local branch git checkout -b <new_branch_name> <sha1>


Note: to "undo" (return from) the detached head state, simply use:

git checkout <branch> (where <branch> is e.g. master).

Answer from Marcelo Cantos on Stack Overflow
🌐
GitKraken
gitkraken.com › home › learn › git checkout
Git Checkout - Checkout Branches, Commits, & Tags | Learn Git
March 26, 2026 - From here, the branch pointer will continue to follow each new commit made on the branch. It is also possible to Git checkout a commit. This will update your repository’s files to match the snapshot of the commit you have checked out.
🌐
Git Tower
git-tower.com › learn › git faq › how to checkout a commit in git
How to Checkout a Commit in Git | Learn Version Control with Git
5 days ago - With the git switch command (or, alternatively, the git checkout command), you can simply provide the name of the branch you want to checkout. This branch will then be your current working branch, also referred to as "HEAD" in Git.
🌐
Git
git-scm.com › docs › git-checkout
Git - git-checkout Documentation
Running git checkout without specifying a branch has no effect except to print out the tracking information for the current branch. ... Create a new branch named <new-branch>, start it at <start-point> (defaults to the current commit), and check out the new branch.
🌐
Atlassian
atlassian.com › git › tutorials › resetting checking out and reverting
Resetting, Checking Out & Reverting | Atlassian Git Tutorial
December 16, 2025 - We explore the three trees in depth on the git reset page. Keep these mechanisms in mind as you read through this article. A checkout is an operation that moves the HEAD ref pointer to a specified commit.
🌐
Medium
medium.com › @Ariobarxan › checking-out-a-commit-in-git-533fe702cf23
Checking out a commit in Git. This article is one of the articles in… | by Ario Liyan | Medium
September 20, 2023 - To check out a specific commit in Git, you can use the git checkout command followed by the commit reference.
Find elsewhere
🌐
GitHub
docs.github.com › en › desktop › managing-commits › checking-out-a-commit-in-github-desktop
Checking out a commit in GitHub Desktop - GitHub Docs
Right-click on the commit you would like to checkout and select Checkout commit. The Current Branch item in the repository bar will now show "Detached HEAD", along with the SHA of the commit that was checked out.
🌐
Reddit
reddit.com › r/git › how can i checkout a previous commit? more details below
r/git on Reddit: How can I checkout a previous commit? More details below
July 28, 2015 -

Something got screwed up at work and our tests isn't passing. The tests were passing about a week ago. I need to checkout commits from last week to identify the issue, but when checking out commits I need to ensure that the commit is a reflection of what our project's code looked like a week ago; in other words, I don't want to roll back on just one file, I'd like to roll back the entire project.

🌐
Medium
medium.com › @gecno › mastering-git-exploring-git-checkout-commit-id-path-4d11ba2a597d
Mastering Git: Exploring git checkout <commit id> <path> | by Gec | Medium
January 17, 2024 - ... Here, you can test how your ... branches. In conclusion, git checkout <commit id> <path> is a valuable command for navigating the history of your project and managing individual file versions....
🌐
CloudBees
docs.cloudbees.com › knowledge base › how to checkout at a given commit in a pipeline
How To Checkout at a given commit in a Pipeline
node { checkout([ $class: 'GitSCM', branches: [[name: ${commitId}]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: ${gitUrl}]]]) sh 'ls -al' }
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › git checkout commit
How do you Git checkout a commit? | Solutions to Git Problems
November 30, 2022 - To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.
🌐
Augustana University
lovelace.augustana.edu › q2a › index.php › 8714 › difference-between-checkout-switch-branch-checkout-commit
What is the difference between git checkout/switch [branch] and git checkout [commit-hash]? - Augustana CSC Q&A
November 25, 2024 - Do `git checkout/switch [branch]` and `git checkout [commit-hash]` have different functions? How ... which one to use and what are their functions?
🌐
CoreUI
coreui.io › answers › how-to-checkout-a-commit-in-git
How to checkout a commit in Git · CoreUI
November 18, 2025 - The git checkout command with a commit hash puts your repository in “detached HEAD” state, allowing you to examine files and run tests without affecting any branch. You can use the full 40-character hash or a shortened version (typically ...
🌐
DevOps Cube
devopscube.com › checkout-clone-specific-git-commit-id-sha
How to Checkout/Clone From a Specific Git Commit Id (SHA)
March 14, 2025 - Step 3: Copy the commit (SHA) id and checkout using the following command. git checkout 28cd74decb47d8a5294eb59e793cb24a0f242e9e
🌐
Dal
phys.ocean.dal.ca › ~jpaucl › Git › Checkout
JP's Wiki | Git / Checking out
Through the log, one has access to all the versions of the code that has been committed. Each can be accessed using · git checkout CommitHash
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Basic-Branching-and-Merging
Git - Basic Branching and Merging
Figure 18. A simple commit history · You’ve decided that you’re going to work on issue #53 in whatever issue-tracking system your company uses. To create a new branch and switch to it at the same time, you can run the git checkout command with the -b switch:
🌐
GoLinuxCloud
golinuxcloud.com › home › devops › git › git checkout command explained (branch, commit, file examples)
Git Checkout Command Explained (Branch, Commit, File Examples) | GoLinuxCloud
March 16, 2026 - This command restores every tracked file to the state of the latest commit. You can also clean untracked files using git clean. ... The git checkout command supports several options that simplify common Git workflows such as creating branches, ...
🌐
Git
git-scm.com › cheat-sheet
Git Cheat Sheet
git commit -am 'message' git switch <name> OR git checkout <name> git switch -c <name> OR git checkout -b <name> git branch · git branch --sort=-committerdate · git branch -d <name> git branch -D <name> git diff HEAD · git diff --staged · git diff · git show <commit> git diff <commit> <commit> git diff <commit> <file> git diff <commit> --stat git show <commit> --stat ·