Remove Last Commit and Discard Changes
GitLab 👶 Easy Git
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.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →