GIT · History · 10 min

Commit two edits from one file separately

Use patch staging to separate independent configuration changes.

Not completed

Your task

Commit the timeout change first, then the retries change. The first new snapshot must have timeout=20 and retries=1; the final snapshot must have timeout=20 and retries=3.

What you’re aiming for

  • Two new commits separate the two settings.
  • The working tree is clean and the final file preserves every comment.

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-commit-separate-hunks && cd opsrung-git-commit-separate-hunks

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' 'A disposable OpsRung practice repository.' > README.txt
git add -- README.txt
git commit -m 'Start practice'
printf '%s\n' 'timeout=10
# stable option 1
# stable option 2
# stable option 3
# stable option 4
# stable option 5
# stable option 6
# stable option 7
# stable option 8
# stable option 9
# stable option 10
# stable option 11
# stable option 12
retries=1' > settings.conf
git add -- settings.conf
git commit -m 'Add configuration'
printf '%s\n' 'timeout=20
# stable option 1
# stable option 2
# stable option 3
# stable option 4
# stable option 5
# stable option 6
# stable option 7
# stable option 8
# stable option 9
# stable option 10
# stable option 11
# stable option 12
retries=3' > settings.conf
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 add -p lets you select individual hunks.

Hint 2

The first hunk changes timeout; the second changes retries.

Hint 3

Accept the first hunk with y, reject the second with n, commit, then stage the remaining edit.

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 show HEAD~1 -- settings.conf
git show HEAD -- settings.conf
git status

What you should see

  • Two new commits separate the two settings.
  • The working tree is clean and the final file preserves every comment.

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
ONE POSSIBLE SOLUTION — BASH
printf 'y\nn\n' | git add -p -- settings.conf
git commit -m 'Increase timeout'
git add settings.conf
git commit -m 'Increase retries'

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.