GIT · Advanced history · 10 min
Find and clean a word throughout local history
Use history search, then rewrite each affected snapshot.
Not completedYour task
Replace noisy with clear in message.txt and notes.txt in every commit reachable from main. Keep the four-commit sequence and other files. This is synthetic text, not a credential-removal procedure.
What you’re aiming for
- No main-history version of either file contains noisy.
- Both current files contain clear and release.txt remains.
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.
mkdir opsrung-git-clean-history-word && cd opsrung-git-clean-history-word
Run these setup commands in that folder:
git init --initial-branch=main git config --local user.name 'Practice Learner' git config --local user.email 'practice@example.invalid' printf '%s\n' 'A disposable OpsRung practice repository.' > README.txt git add -- README.txt git commit -m 'Start practice' printf '%s\n' 'A noisy message.' > message.txt git add -- message.txt git commit -m 'Add message' printf '%s\n' 'A noisy note.' > notes.txt git add -- notes.txt git commit -m 'Add note' printf '%s\n' 'Release intact.' > release.txt git add -- release.txt git commit -m 'Record release'
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.
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 -S finds commits where a string’s count changes.
Hint 2
A rebase with --exec can apply a correction after each replayed commit.
Hint 3
Only rewrite this disposable unpublished history.
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.
git log -S 'noisy' main -- message.txt notes.txt git log --oneline main cat message.txt notes.txt
What you should see
- No main-history version of either file contains noisy.
- Both current files contain clear and release.txt remains.
If your result differs: Work only in this exercise’s repository. Compare the branch, files, and history with every goal before marking complete.
Compare with one possible solution
git log -S 'noisy' --oneline -- message.txt notes.txt GIT_SEQUENCE_EDITOR=true git rebase -i --root --exec 'for file in message.txt notes.txt; do if test -f "$file"; then sed -i '\''s/noisy/clear/g'\'' "$file"; git add -- "$file"; fi; done; if ! git diff --cached --quiet; then git commit --amend --no-edit; fi'
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.