78. Undo Commits but Keep Changes
Beginner Mode
Start your terminal to use beginner mode.
Scenario:
You have a Git repository at /home/interview/repo with three recent commits on the main branch that were premature and need to be reorganized.
Task:
Undo the last three commits while keeping all changes in your working directory so you can recommit them properly.
Example:
# Before (three commits exist)
$ git log --oneline -4
d4e5f6a Third commit
c3d4e5f Second commit
b2c3d4e First commit
a1b2c3d Initial commit
# After (commits undone, changes kept)
$ git log --oneline -2
a1b2c3d Initial commit
$ git status
On branch main
Changes to be committed:
modified: file1.txt
modified: file2.txt
modified: file3.txt
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 →
CrowdStrike
Accenture
Coinbase
Adobe
EPAM
Twitch
Amazon
Kayak
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
Ubisoft
Anthropic
Capital One
Splunk
Intel
AMD
Databricks