71. Remove Last Commit and Discard Changes
Beginner Mode
Start your terminal to use beginner mode.
Scenario
You have created a commit locally that contains incorrect changes and you want to completely erase it from history.
Task
Navigate to /home/interview/repo. Remove the last commit entirely and discard all associated file changes.
Example
# Before (Bad commit exists)
$ git log --oneline -2
c3d4e5f (HEAD -> main) Bad commit - wrong changes
b2c3d4e Add feature implementation
# After (Clean history)
$ git log --oneline -2
b2c3d4e (HEAD -> main) Add feature implementation
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 →
GitLab
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
Shopify
Samsung
Elastic
Twilio
Netflix
CrowdStrike
Ubisoft
Anthropic
Capital One
Splunk
Intel
AMD
Databricks