Courseiva
hardMultiple ChoiceObjective-mapped

Undo Commit with Git Revert

A developer accidentally committed a bug that broke the build. The team wants to undo the commit without losing the commit history. Which Git command should be used?

Quick Answer

The answer is git revert HEAD, because it creates a new commit that reverses the changes from the previous commit while preserving the full commit history. Unlike git reset, which removes commits and rewrites history—a dangerous practice on shared branches—git revert is the safe, non-destructive way to undo a commit. On the CompTIA ITF+ FC0-U61 exam, this question tests your understanding of version control fundamentals, specifically the difference between commands that alter history versus those that add to it. A common trap is confusing git revert with git reset, but remember: revert adds a new undo commit, while reset erases commits entirely. For a quick memory tip, think of revert as “reverse and record”—it logs the fix so the team can see exactly what was undone, keeping the build’s timeline intact.

⚠ Common exam trap

Test-takers frequently confuse `git revert` (safe, history-preserving) with `git reset` (destructive, history-rewriting), often choosing `git reset` because it seems simpler, but it violates the requirement to keep the commit history intact.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

git revert HEAD

`git revert HEAD` creates a new commit that undoes the changes introduced by the most recent commit, preserving the full commit history. This is the only safe way to undo a commit that has already been pushed or shared, as it does not rewrite history.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • git reset HEAD~1

    Why it's wrong here

    git reset rewrites history and can cause issues for other developers.

  • git checkout HEAD~1

    Why it's wrong here

    git checkout is not for undoing commits; it moves the HEAD pointer.

  • git revert HEAD

    Why this is correct

    git revert creates a new commit that undoes the changes, keeping history intact.

  • git branch -d bugfix

    Why it's wrong here

    git branch -d deletes a branch, not reverted a commit.

About these practice questions

One of 988 original FC0-U71 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on FC0-U71

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A team is using version control for a software project. A developer accidentally committed a buggy change to the main branch. Which action should the team take to fix this while preserving the commit history?

medium
  • A.Ask all developers to manually undo the changes in their local copies.
  • B.Use the revert command to create a new commit that undoes the changes.
  • C.Delete the repository and start over.
  • D.Force delete the commit from history.

Why B: The `git revert` command creates a new commit that undoes the changes introduced by a previous commit, effectively fixing the buggy code while preserving the full commit history. This is the standard, safe approach in Git for undoing changes on a shared branch like main, as it does not rewrite history or require force-pushing.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This FC0-U71 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the FC0-U71 exam.