How do you check out a specific commit in Git?

How do you check out a specific commit in Git?

a) git checkout commit-hash
b) git revert commit-hash
c) git checkout branch-name
d) git pull commit-hash

Answer:

a) git checkout commit-hash

Explanation:

The git checkout commit-hash command checks out a specific commit by its hash. This places your repository in a detached HEAD state, allowing you to view or work with the project at the state of that commit.

For example, running git checkout abc123 will check out the commit with hash abc123.

Be aware that if you make new commits in this state, they won’t be attached to any branch unless you create a new one.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top