GIT · History · 8 min

Undo a change without erasing history

Create an inverse commit instead of moving the branch backwards.

Not completed

Your task

Revert the latest commit so settings.json matches the original safe configuration. Preserve the bad commit in history and add exactly one inverse commit.

What you’re aiming for

  • There are three commits, with the bad commit still in the chain.
  • The latest tree matches the original safe tree.
  • The working tree is clean.

1. Prepare your practice folder

Use Git 2.28 or newer. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-git-revert-bad-commit && cd opsrung-git-revert-bad-commit

Run these setup commands in that folder:

SETUP — RUN ONCE
git init --initial-branch=main
git config --local user.name 'Practice Learner'
git config --local user.email 'practice@example.invalid'
printf '%s\n' '{"feature":false,"timeout":30}' > settings.json
git add settings.json
git commit -m 'Safe configuration'
printf '%s\n' '{"feature":true,"timeout":0}' > settings.json
git add settings.json
git commit -m 'Enable unreviewed configuration'
Only if your personal Git settings interfere

You can normally skip this. If a commit asks for a signing key, runs a custom hook, or changes line endings unexpectedly, these repository-local overrides keep this disposable exercise independent of those settings.

OPTIONAL REPOSITORY OVERRIDES
git config --local commit.gpgsign false
git config --local core.autocrlf false
git config --local core.hooksPath .git/practice-no-hooks

Retry the failed command afterward. These settings apply only inside this practice repository.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

git log --oneline shows which commit introduced the bad configuration.

Hint 2

A reset would remove the bad commit from this branch. The task asks for an inverse commit.

Hint 3

git revert --no-edit HEAD creates the inverse commit without opening an editor.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
git log --oneline
git diff HEAD~2 HEAD
git status

What you should see

  • git log --oneline lists three commits, including the bad commit and a new revert commit.
  • git diff HEAD~2 HEAD produces no output: the original safe settings are restored.
  • git status reports a clean working tree.

If your result differs: Resetting to an older commit removes the bad commit from the branch history. This task asks for a new inverse commit using git revert.

Compare with one possible solution
ONE POSSIBLE SOLUTION
git revert --no-edit HEAD

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.