GIT · History · 10 min
Split a mixed commit into two
Give unrelated files their own history entries.
Not completedYour task
Replace the latest mixed commit with two commits: first api.txt, then docs.txt. Preserve both files and the initial commit.
What you’re aiming for
- The latest two commits each introduce only their named file.
- The history contains three commits.
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-split-combined-commit && cd opsrung-git-split-combined-commit
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' 'Validate record ownership.' > api.txt printf '%s\n' 'Describe the access rule.' > docs.txt git add api.txt docs.txt git commit -m 'Mixed changes'
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
A mixed reset can undo the commit while keeping the files.
Hint 2
Stage and commit one file at a time.
Hint 3
Reset HEAD~1, then commit api.txt before docs.txt.
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 status git log --oneline --graph --all -12
What you should see
- The latest two commits each introduce only their named file.
- The history contains three commits.
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 reset HEAD~1 git add api.txt git commit -m 'Add access rule' git add docs.txt git commit -m 'Explain access rule'
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.