Chapter 3. Version control and change review
Learning objectives
- Explain the relationship among the working tree, staging area, commit history, and remote repository.
- Select comparison targets to read diffs, and identify out-of-scope modifications and changes that weaken checks in agent changes.
- Create commits with a single purpose, and selectively commit changes within a single file.
- Choose the appropriate Revert method among restore, reset, revert, and stash depending on whether changes have been shared.
- Recover lost commits with reflog, and resolve conflicts while preserving the intent of both changes.
Introduction
Coding agents modify dozens of files in a few minutes. While they handle work that would take a human an entire day, it is equally easy to miss what has changed. An agent's report might be a single line saying "Added a date filter," but in reality, a date calculation function may have been completely rewritten, a new package may have been introduced, and a test may have been quietly turned off.
Git is what reveals this difference. Git shows what has changed line by line, and records states you like so that you can return to them at any time. When working with an agent, Git is not an option but a safety net. The reason you can entrust bold attempts to an agent is that you always have a point to revert to.
This chapter begins with Git's basic structure and covers how to read and review diffs, how to use commits and branches, how to resolve conflicts, and how to revert appropriately according to the situation. In Going deeper, we look at recovering lost commits, rewriting shared history, and running multiple agents simultaneously.
Key concepts
Git is a time machine with save points
Git is a version control tool that records the change history of files. Just like save points in a game, if you record every state you like, you can return to that state at any time. These save points are called commits, and each commit is accompanied by a message stating why the change was made. GitHub documentation refers to these records as point-in-time snapshots.
In Git, changes pass through three areas.
| Area | Metaphor | Description |
|---|---|---|
| Working tree | Workbench | Where you are currently modifying files |
| Staging area (index) | Packing box | Where changes selected to be included in the next commit are gathered |
| Commit history | Warehouse shelf | Where finalized save points are stacked |
HEAD is a pointer indicating the most recent commit of the currently checked-out branch, serving as 'the save point where you currently stand'. The current state is viewed with git status. In git status --short, M means that a tracked file has been modified, and ?? means a new file that Git is not yet tracking. Form a habit of checking whether this output is clean before delegating work to an agent. Codex documentation also recommends working on a feature branch, keeping git status clean before delegating tasks, and committing frequently to make reverting easy.
History on my computer and the remote repository
According to GitHub documentation, Git is distributed, so every developer has a copy of the entire project and its history. The repository on my computer is called local, and the repository on a shared server like GitHub is called remote.
| Command | What it does |
|---|---|
git clone |
Downloads the entire remote repository for the first time |
git fetch |
Fetches new remote history without merging it into my work |
git pull |
Merges the fetched history into my branch |
git push |
Pushes my local commits to the remote |
This distinction is important because the method to revert differs depending on whether changes have been shared. Commits that have not yet been pushed are records held only by you, so you can delete or rewrite them. If you delete a commit that has already been pushed and fetched by others, it will conflict with your coworkers' history.
diff: What is being compared with what?
A diff shows the difference between two states line by line. What tells you most accurately what an agent has done is not its report, but the diff. However, even with the same git diff, what is shown differs depending on what is being compared with what.
git diff # Compares working tree and staging area: changes not yet staged
git diff --staged # Compares staging area and last commit: changes to go into the next commit
git diff HEAD # Compares working tree and last commit: all changes since the commit
git diff main...feature # Changes in feature since the point where the two branches diverged
--staged has the same meaning as --cached. For large changes, start with a summary. --stat shows how many lines changed per file, and --name-only shows only the names of modified files. If an agent made massive changes to indentation or trailing whitespace that obscure the real changes, ignore whitespace differences with -w, and view small changes within a single line at the word level using --word-diff.
Newly created files are not yet tracked by Git, so they do not appear in git diff. Confirm whether the agent created new files from the ?? indicator in git status, stage them, and then view their contents with git diff --staged.
diff review order and checklist
Trying to read every line with equal depth will exhaust you. Check the scope first, and read deeply starting from risky areas.
- Check the scope. Scan the number and locations of files with
git diff --stat. If there are too many files relative to the request, suspect that first. - Open risky areas first. If authentication, payments, permissions, configuration files, database schemas, or dependency lists (
package.jsonand lock files) have changed, check whether the reason is clear. - Look for what disappeared. Find deleted tests, erased error handling, and missing inspection steps.
- Look at individual values. Just as sorting order flips from
a.date - b.datetob.date - a.date, a small change within a single line can drastically alter behavior. - Look for things that should not be included. Check that secrets, build artifacts, temporary files, and logs have not been mixed in. Prevent such files from being tracked altogether using
.gitignore(Chapter 4). - Ask about changes you do not understand. Do not accept changes that cannot answer "Why was this file changed?"
Changes that weaken checks
When asked to eliminate failures, agents sometimes weaken checks instead of fixing the application. It is like removing the batteries from a smoke detector because the alarm is ringing. Look for the following signals in the diff.
| Signal | Appearance |
|---|---|
| Test deletion | Entire test files or test blocks disappear |
| Skipping | Markers like it.skip, describe.skip, or xit appear |
| Relaxed expected values | Concrete value comparisons change to an "exists" level; expected values change to actual values |
| Check-disabling comments | Comments that disable type checking or linting newly appear |
| Relaxed configuration | Strict type-checking options are turned off, or folders are excluded from check targets |
| Deletion of automation steps | Test or lint steps are removed from CI configuration |
Because tests may need to change when requirements change, the criterion is "Is there a requirement that justifies that change?" If not, revert it.
Keep commits small, with a single purpose
GitHub flow guidance states that each commit should include an explanation of what changed, and ideally, a single commit should contain a single independent and self-contained change. Only then is it easy to selectively revert only that change later. If a 'wording change' and an 'authentication logic change' are mixed in one commit, even if you want to revert only authentication, you must manually pick out the necessary parts and verify them again. In particular, do not mix formatting cleanup (indentation, quotation marks) with functional changes. If formatting changes span hundreds of lines, real changes will be buried inside them.
If an agent leaves both necessary and unnecessary modifications within a single file, selectively stage them with git add -p. Git displays changes in units of hunks (contiguous chunks of changes) and prompts you one by one.
| Key | Meaning |
|---|---|
y |
Stage this hunk |
n |
Do not stage this hunk |
s |
Split the hunk into smaller parts |
e |
Manually edit the hunk in an editor |
q |
Quit; do not stage this hunk or any of the remaining hunks |
Write why along with what in commit messages. Rather than "Fix bug", "Fix issue where morning reservations failed format validation" is much more useful three months later.
Branch and pull request flow
A branch is a separate line of work diverged from the main flow (usually main). It is like a test shoot conducted separately from the main production. The sequence recommended by GitHub flow guidance is as follows.
- Create a branch with a short, descriptive name. Create separate branches for unrelated changes.
- Accumulate commits with descriptive messages on the branch.
- Open a pull request (PR), write a summary of the changes, and request a review. Respond to review comments by pushing more commits to the same branch.
- Once approved, merge it and delete the branch. The PR and commit history remain.
Branches are especially useful when entrusting large tasks to agents. If you do not like the outcome, you can leave main untouched and discard the branch entirely, and if a preview deployment is generated for each PR (Chapter 5), you can also see the actual screen before merging.
Resolve conflicts by meaning
When two branches modify the same line of the same file differently, Git stops because it does not know which side to choose. GitHub documentation explains that conflicts occur when the same line is changed differently, or when one side modifies a file and the other deletes it, and all conflicts must be resolved before merging can proceed. Markers remain in conflicted files.
<<<<<<< HEAD
const MAX_GUESTS = 8;
=======
const MAX_GUESTS = 6;
const WAITLIST_ENABLED = true;
>>>>>>> feature/waitlist
Above ======= is the current branch (HEAD) side, and below is the side being merged. Resolving a conflict is not merely erasing the markers, but deciding on a result that preserves the intent of both changes. In the example above, after confirming why the "decision to increase the capacity to 8 guests" and the "decision to enable the waitlist feature" were made, write code in which both remain intact. If you accept one side entirely, the decision from the other side quietly disappears.
When delegating conflict resolution to an agent, inform it of the respective purpose of both changes, and have it run the tests again after resolution. If you cannot make a clear judgment while resolving, you can return to the pre-merge state with git merge --abort. Git documentation notes that this command may not fully restore uncommitted changes, so it recommends committing or stashing before merging.
Revert decision table
Revert commands differ in what they revert and how they handle history.
| Command | Target handled | When to use | Cautions |
|---|---|---|---|
git restore <file> |
Working tree changes before commit | When discarding content just modified | Defaults to restoring to the contents of the staging area. If you discard unstaged modifications, they cannot be recovered with Git |
git restore --staged <file> |
Staging area | When canceling staging only | Modifications in the working tree remain as they are |
git stash push -u |
Pre-commit changes and untracked new files (ignored files only with --all) |
When temporarily shelving changes that are too valuable to discard | apply applies while keeping them in the list; pop deletes them from the list if application succeeds |
git reset --soft <point> |
Commit history only | When squashing multiple commits that have not yet been shared into one | Changes from the reverted commits remain in the staging area as they are |
git reset --hard <point> |
All of history, staging, and working tree | When discarding unshared local commits entirely | Uncommitted changes are also overwritten |
git revert <commit> |
Already recorded commit | When reverting the effects of a shared commit | Leaves the inverse change as a new commit without deleting history. The working tree must be clean |
reset also has --keep. It discards commits while preserving uncommitted modifications, and stops if there are uncommitted modifications in files whose contents differ between the current HEAD and the target point. Git documentation clearly states not to use --hard on commits that have already been given to others.
Key point
The decision order is simple. If you have not committed yet, it is restore or stash; if you committed but have not shared with anyone, it is reset; and if you already pushed and others have fetched it, it is revert.
Because a merge commit (a commit that combined branches) has more than one parent, you must specify which side to base the reversion on using -m (usually -m 1). Git documentation warns that reverting a merge commit is a declaration that you do not want the changes brought in by that merge going forward, so even if you merge the same branch again later, those changes will not be brought back automatically.
The agent's rewind feature and Git
Whenever sending a request to start a new turn, Claude Code creates a checkpoint to save the file state. When the input box is empty, pressing Esc twice or opening the menu with /rewind allows you to revert only code, only conversation, or both to a previous point. While convenient, the limitations stated in the official documentation are clear.
- It tracks only content changed through the agent's file editing tools. Files modified by shell commands like
rm,mv, orcpcannot be reverted. - It usually cannot capture files modified directly by humans or edits from other concurrently running sessions.
- Files modified by subagents are generally not restored.
- Snapshots are cleaned up by default after about 30 days.
- It does not replace version control. Continue using Git for permanent history and collaboration.
Rewind is an auxiliary means to quickly undo mistakes within a session. The real safety net is commits made at verified points. Even in modes that permit writing to the workspace folder, Codex protects the .git directory as read-only to prevent agents from corrupting the history itself.
Secrets are filtered once more at the push stage
It is not uncommon for agents to write API keys directly into code to run tests. If you missed this during diff review, the next line of defense is GitHub's push protection. GitHub documentation introduces this feature as a secret scanning capability that prevents hardcoded credentials such as secrets or tokens from being pushed to repositories in the first place.
The default value depends on the level at which it is enabled.
| Classification | Default | Scope |
|---|---|---|
| User-level push protection | Enabled | Blocks secrets in pushes to public repositories |
| Repository-level push protection | Disabled | Works only when enabled in the repository |
Secret scanning itself runs automatically and free of charge on public repositories. To use it on organization-owned private or internal repositories, GitHub Secret Protection is required (documentation as of 2026-11-01). The detection targets also continue to expand. On 2026-03-10, GitHub enabled push protection by default for 39 detectors, including Airtable, Databricks, Heroku, PostHog, and Shopify.
When a push is blocked, that is the moment to judge. It might seem that adding one more commit to delete the key would suffice, but the key remains in the prior commit and gets pushed along with it. Since this is history that has not yet been pushed, it can be rewritten. When Jiho stacked two more commits on top of the commit where he put a payment key into config.ts, he unpacked the three commits with git reset --soft HEAD~3, moved the key to an environment variable, and committed again. If the key had already been exposed through another path, a new key had to be issued separately from cleaning up the history.
Key point
Organization-owned private repositories do not have push protection enabled by default. First confirm whether repository-level push protection is enabled and whether GitHub Secret Protection is available.
Difference between CLAUDE.md rules and hooks
Teams often write rules in CLAUDE.md so that agents do not use dangerous Git commands, such as a single line: "No git push --force to shared branches." However, Claude Code documentation reveals that Claude treats CLAUDE.md as context, not as enforced configuration. Rules are merely material for judgment, not mechanisms that prevent execution. If a specific action must be blocked regardless of what Claude decides, use a PreToolUse hook.
| Mechanism | Nature | Appropriate use |
|---|---|---|
| CLAUDE.md | Context, guidance | Commit message format, branch naming conventions, review order |
| PreToolUse hook | Interception before tool execution | Force pushes, git reset --hard, modifying files that must not be touched |
Which of the two to rely on is decided by how easy it is to revert when violated. If a commit message format is slightly off, correcting it in the next commit is all it takes. A force push that overwrote a coworker's commit is a different story.
Minseo's team, who was building a book rental app, wrote "Do not rewrite shared branch history" in CLAUDE.md. However, the agent attempted to execute git push --force while resolving conflicts. The team decided to block force pushes to shared branches using a hook, and in CLAUDE.md, they recorded the rationale for the rule and the alternative, git revert. Hooks block actions, while documentation helps agents choose a different path from the start. Enabling protected branches on the remote as well catches it once locally and once remotely.
Examine dependency diffs down to their source and timing
Even if the diff of package.json and lock files contains few lines, do not pass over it lightly, because a single line with a package name brings in all the code written by others. If it is a package added by an agent, first confirm whether a package with that name actually exists and is not an unrelated package with merely a similar name. A study published in USENIX Security 2025 analyzed 576,000 code samples generated in Python and JavaScript by 16 LLMs, addressing package hallucinations where models fabricate non-existent packages.
For Dependabot PRs, examine the timing as well. Based on current documentation, if cooldown is not configured, Dependabot applies a default 3-day grace period to version updates. Previously, it suggested updates as soon as a new version was released without any default grace period. This default value does not apply to security updates.
| PR type | Default grace period (cooldown not configured) |
What to review |
|---|---|---|
| Version update | 3 days | Changelog, subpackages changed together in the lock file |
| Security update | None | Fixed vulnerabilities, scope of impact, test results |
When Haeun, who managed a craft workshop reservation app, received a Dependabot PR on the day a new version was released, she first checked its type. Because it was normal for security updates to arrive without a grace period, she confirmed the fixed vulnerabilities and test results. If it was a version update, she checked whether cooldown was specifically configured in the configuration file. Starting from 2026-10-20, repositories upgraded to npm 12, pnpm 11 or 12, or Bun 1.4 also continue to receive Dependabot updates. Upgrading package managers does not cut off PRs.
Going deeper
Recovering lost commits: reflog
Even if commits disappear from git log after accidentally running git reset --hard, most can be recovered. This is because Git records every movement of a branch tip in the reflog (reference log). Commits you thought were deleted remain inside the repository for a period of time.
git reflog # List of positions HEAD has passed through
# a1c9e02 HEAD@{0}: reset: moving to HEAD~2
# 7f3b8d1 HEAD@{1}: commit: Add recurring payment notice text
git branch rescue 7f3b8d1 # Revive the lost commit by attaching a branch
HEAD@{2} means "where HEAD was two steps ago." If you are undoing a reset you just ran, you can also use git reset --hard ORIG_HEAD (the position immediately before the reset remains in ORIG_HEAD. Other commands like merge or rebase overwrite this value, so use it right away). However, the reflog does not last forever. According to the Git documentation, the default retention period is 90 days for entries reachable from the current branch and 30 days for unreachable entries. In addition, the reflog is a local record, so it cannot contain changes that were never committed. If modifications that were never staged are overwritten with --hard, they cannot be recovered with Git. Staged content remains as Git objects and has a chance of being found with git fsck --lost-found, but it is better not to rely on this.
Rewriting shared history
Before pushing, cleaning up messy commits is fine. As in the example from the Git documentation, running git commit after git reset --soft HEAD~5 squashes the last five commits into one. The problem arises when rewriting history that has already been pushed.
Uploading rewritten history requires a force push. git push --force overwrites without checking the remote state. If a teammate pushed a new commit to the same branch while you were fixing history, that commit will disappear. git push --force-with-lease overwrites only when the remote branch is still at the exact point where you last fetched it, and is rejected if it moved in the meantime. However, the Git documentation warns that if git fetch runs automatically in the background, the 'last seen state' can be quietly updated and disable this protection, and introduces how to use --force-if-includes alongside it.
GitHub blocks force pushes on protected branches by default. It is best to minimize the need to rewrite history on shared branches in the first place. Keep feature branches short, and clean up before pushing.
Making commits directly on local main without a feature branch is also a common mistake. Before pushing to the remote, you can hold onto the commits by first attaching a branch name to the current position (git branch <new-branch>), reset main back to the same point as the remote (git reset --hard origin/main), and then switch to the new branch to continue working. The order is important. If you reset before creating the branch, the commits will remain only in the reflog.
Running multiple agents concurrently
When multiple agent sessions work simultaneously in a single folder, they take turns modifying the same files, and different tasks easily get entangled in a single commit. It is like two chefs sharing one cutting board in a single kitchen. The solution is a worktree. According to the Git documentation, you can attach multiple working trees to a single repository and check out different branches at the same time.
git worktree add -b feature/coupon ../shop-coupon # New branch in a new folder
git worktree list
git worktree remove ../shop-coupon # Clean up when finished
Claude Code creates a worktree for a new branch under .claude/worktrees/<name>/ in the repository with claude --worktree <name> and starts a session inside it. Because each session has a separate copy of the files, edits do not collide. Since a worktree is a newly checked-out copy, it lacks ignored files such as .env; therefore, the Claude Code documentation instructs copying necessary files using .worktreeinclude, a configuration file dedicated to this tool, and adding .claude/worktrees/ to .gitignore.
Concurrent execution is also useful for reviews. Claude Code best practices state that a fresh context conducts code reviews better. This is because it is not biased toward code that was just written. There is an author-reviewer approach where one session implements and another session reviews, or an approach where a subagent is given only the plan file and diff to find missing requirements and out-of-scope changes. However, the documentation adds that a reviewer instructed to find flaws will invariably report something even when the work is completely sound, so you should only accept feedback that affects correctness and requirements.
At work
Wind Path Bikes: Nine files changed for a single sort
Seoyeon, the operator of the shared bicycle rental shop "Wind Path Bikes," asked an agent, "Please sort the rental list in order of scheduled return time." The agent reported Done, and the tests also showed Pass. Out of habit, Seoyeon looked at git diff --stat first. For a task that seemed to require only two files, nine files had changed.
Glancing through, there were three categories. Modifications to the list screen and the sort function were exactly as requested. Five files were formatting cleanups where only quotes and indentation had changed. In addition, a new date library had entered package.json and the lock file, and it.skip had been added to one test calculating the return time. A test marked with skip does not run and is only displayed as skipped, so one of the reasons the tests showed Pass was that skipping.
Seoyeon weighed three options.
- Accept as is: Convenient because the tests showed Pass. However, disabled tests and a new dependency would be left in history without even knowing the reason. Rejected.
- Discard everything and delegate again: Clean, but it would also discard the sort modifications that were done as requested. Rejected.
- Cherry-pick: Commit only the necessary changes and revert the rest. She chose this.
When asked for the reason, the agent replied, "I added the library because handling time zones with standard date comparison was cumbersome, and because of that, the results differed from the existing test, so I skipped it." Seoyeon stripped away formatting changes with the -w option and looked at the diff of only the sort function again. Sorting was possible even with existing date comparisons. Seoyeon had it fixed without the library, revived the skipped test, and ran All tests. Because formatting changes were mixed in the file containing the sort function as well, she selected only the sort hunk with y and the formatting hunk with n using git add -p. The remaining formatting files were reverted using git restore.
She left the commit message as "Sort rental list in order of scheduled return time." If formatting cleanup were needed, she decided to do it separately next time in a commit containing only that. If she had accepted it seeing only test Pass, a disabled check and a dependency no one knew about would have been mixed into the history.
One Light Choir: Friday's commit, Monday's discovery
Taemin, the general manager of "One Light Choir," which runs a member attendance management app, received a message on Monday morning: "The attendance rate is showing up strangely low." On Friday afternoon, it was normal. In the meantime, eleven commits uploaded by Taemin and two other volunteers had accumulated on main, and all had already been pushed to the remote.
There were too many commits to open one by one to see which commit was the cause. Because there were no tests to confirm the attendance rate, Taemin first had an agent write a small script that calculated the attendance rate with Friday's data and compared it to the expected value. It was a script that returned exit code 0 if equal to the expected value, 1 if different, and returned 125 to skip on commits that could not be confirmed because they did not build. Then, he ran Git's binary search.
git bisect start HEAD <Friday normal commit>
git bisect run node scripts/check-attendance.mjs
git bisect reset
git bisect checks out the middle commit between good and bad, runs the script, and halves the range depending on the result. The root-cause commit emerged in just four tries. It was a commit where, while adding absence reasons, the condition was changed to count 'Excused absence' as an absence.
One volunteer suggested resetting history entirely back to the Friday point and overwriting the remote. Taemin refused. Erasing history that two people had already pulled would cause mismatches with their local environments, and ten commits unrelated to the root cause would also disappear with it. Taemin ran git revert on only that single commit.
A conflict occurred during the revert. This was because after the root-cause commit, another volunteer had added 'Late' attendance handling to the same function. Before clearing the conflict markers, Taemin sorted out the intentions of both sides. What needed to be reverted was 'the condition that counted excused absences as absences', and what needed to be preserved was 'late attendance handling'. He wrote code that preserved both, ran the attendance rate script and All tests again, and then pushed. He moved the attendance rate script directly into the tests so that if the same mistake were introduced again, it would be caught in CI.
Common mistakes
- "The tests passed, so there is no need to look at the diff." A Pass provides peace of mind. However, a Pass does not mean the scope is correct. It may have passed because tests were deleted or turned off.
- "Erasing problematic commits with reset and force-pushing makes things clean." The history looks clean. However, rewriting shared history creates discrepancies with colleagues' history and can even wipe out someone else's work. Revert shared commits with revert.
- "Committing once at the end of the day is enough." Having fewer commits makes the history look simple. However, with large commits, it is difficult to select and Revert only a portion, and the selected result must be verified again. Commit in small, verified units.
- "If nothing shows up in
git diff, nothing has changed." When a command is silent, it feels clean. However, new files do not appear because they are not yet tracked, and staged changes only appear when viewed with--staged. Checkgit statustogether. - "Conflicts are resolved quickly if you accept one side entirely." The markers disappear quickly. However, the other side's decisions are silently erased. Confirm the intent of both sides, preserve both, and run the tests again.
- "Because the agent has rewinding, we can commit less often." Rewinding is convenient. However, it cannot Revert files changed by shell commands or edits from other sessions, and it does not replace Git.
Summary at a glance
| Topic | What to remember |
|---|---|
| Three areas | Working tree → staging → commit. Confirm with git status, ?? indicates new files |
| Whether shared | History before a push can be rewritten, but after a push, use revert |
| diff | Plain git diff is unstaged, --staged is the next commit, HEAD is everything since the commit |
| Review order | --stat → risky files → things that disappeared → single values → things that must not be mixed |
| Weakened checks | Deletion, skip, relaxed expected values, disable comments, relaxed configuration, CI step deletion |
| Commit | Single purpose, separate formatting from functionality, selectively stage with git add -p, state reasons in the message |
| Conflicts | Preserve both intents rather than erasing markers. If unsure, git merge --abort |
| Revert | Uncommitted changes use restore/stash, unshared commits use reset, shared commits use revert. Merges use -m |
| Recovery | Find the position with reflog and attach a branch. Uncommitted changes cannot be captured |
| Concurrent work | A worktree per session. Review in a new context |
Check the official docs
- GitHub: About Git — Distributed version control, commits and branches, basic flow
- GitHub: GitHub flow — Branches, commits, PRs, merging, branch deletion
- Git: git-diff — Comparison forms and
--staged,--stat,-w,--word-diff - Git: git-reset —
--soft,--mixed,--hard,--keep - Git: git-revert — Recording inverse commits, merge commits, and
-m - Git: git-reflog — Reference logs and retention periods
- Git: git-merge — Conflict markers and resolution,
--abort - Claude Code: Checkpointing — Scope and limitations of checkpoints
- GitHub — About push protection: Default values and blocking scope for user-level and repository-level push protection.
- GitHub — About secret scanning: Free automatic execution on public repositories and GitHub Secret Protection required for organization private and internal repositories.
- Claude Code — Memory: That CLAUDE.md is context, not enforcement, and criteria for delegating actions that must be blocked to PreToolUse hooks.
- GitHub — Dependabot options reference: The default three-day cooldown applied to version updates when
cooldownis not configured, and exceptions for security updates.
Self-check
3-1. What does each of git diff, git diff --staged, and git diff HEAD compare against what? Which one do you use to view both staged and unstaged changes all at once?
3-2. The agent reported that it created a new file named src/lib/receipt.ts, but nothing shows up in git diff. Why is this? How do you view the contents of this file as a diff?
3-3. While fixing one feature, the agent changed the indentation of ten files from tabs to spaces. Because the diff is thousands of lines long, it is difficult to find the real changes. Which option should be used to see only the real changes? How should commits be split?
3-4. On an already shared main, you want to Revert a merge commit that combined a feature branch. What must be additionally specified for git revert? When fixing the same branch and merging it again after the Revert, what should you be careful of?
3-5. You put experimental changes into a stash and want to apply them identically to two other branches. Which is appropriate between git stash apply and git stash pop? What is the reason?
3-6. You want to discard two local commits that have not been pushed yet. However, there are uncommitted modifications to other files in the working tree, and you want to keep them. What reset mode can be used instead of --hard, and in what cases does that command stop?
3-7. You are writing a confirmation script to pass to git bisect run. Certain commits do not even build, making it impossible to determine whether they are normal. What exit code should the script return for such commits?
Hands-on tasks
Exercise
Four ways of Revert and recovery (45 minutes)
- In a new folder, create a repository with
git init, modify a file three times, and commit each time. - Without committing the fourth modification, set it aside with
git stash push, restore it withgit stash apply, and this time discard it withgit restore. - Revert the second commit with
git revertand confirm that a new commit has been created ingit log --oneline. - Make a commit on a new branch and discard it with
git reset --hard HEAD~1. - Find the commit you just discarded in
git reflogand recover it withgit branch rescue <hash>.
Done when: The output of git log --oneline is recorded for each step, the difference that revert increases history while reset reduces it is demonstrated, and it can be shown through output that the recovered commit is on the rescue branch.
Exercise
Selectively staging agent changes (45 minutes)
- In a practice app, assign a small feature to an agent, deliberately adding "while you're at it, clean up the code formatting too."
- Before committing, use
git diff --stat,git diff -w, andgit statusto distinguish functional changes, formatting changes, and new files, and write them down in a table. - Look for any changes that weakened checks (deletions, skips, changes to expected values), and if present, ask for the reason.
- Selectively stage only functional changes using
git add -pto create the first commit, and create formatting changes separately as a second commit. - Run tests on each of the two commits to confirm that they Pass.
Done when: The two commits each contain only a single purpose (confirmed with git show --stat), the change classification table and the results of confirming whether checks were weakened remain, and there is output showing that tests Pass on both commits.