80. Recover Lost Commits from Detached HEAD
Beginner Mode
Start your terminal to use beginner mode.
Scenario:
You have a Git repository at /home/interview/repo where you were in a detached HEAD state, made 3 commits, then switched back to the main branch. Those 3 commits are now unreachable and appear to be lost since no branch references them.
Task:
Navigate to the repository at /home/interview/repo, check the reflog to locate the lost commits from the detached HEAD state, create a new branch called recovered-work pointing to those commits.
Example:
# Before (commits lost, only main visible)
$ git log --oneline -3
c3d4e5f Main branch work
b2c3d4e Second commit
a1b2c3d Initial commit
$ git branch
* main
# After (commits recovered in new branch)
$ git branch
* main
recovered-work
$ git log recovered-work --oneline -3
f6a7b8c Third detached commit
e5f6a7b Second detached commit
d4e5f6a First detached commit
Terminal requires a larger screen
Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.
Linux Terminal Environment
Write and execute your solution in the terminal below.
Essential
Linux 0/29
AWS 0/10
Kubernetes 0/15
CI/CD 0/5
Networking 0/9
Need more practice in this area? Explore more questions →
Kayak
Accenture
Coinbase
Adobe
EPAM
Twitch
Amazon
Autodesk
Lyft
Revolut
RedHat
Bloomberg
Datadog
Palantir
TCS
HashiCorp
Google
DeutscheBank
GitHub
Apple
Cloudflare
Stripe
Microsoft
NVIDIA
GoDaddy
X
SAP
Spotify
Airbnb
Meta
Reddit
Yelp
Okta
Dropbox
Slack
ActivisionBlizzard
Zscaler
Uber
IBM
DeliveryHero
Robinhood
GitLab
Shopify
Samsung
Elastic
Twilio
Netflix
CrowdStrike
Ubisoft
Anthropic
Capital One
Splunk
Intel
AMD
Databricks