JavaRush /Courses /Claude Code SELF /Rollback with git in practice

Rollback with git in practice

Claude Code SELF
Level 13, Lesson 4
Available

1. Step 1. Move the work into a branch

Alex is gone, Oliver is on his own. The safe is assembled — Tommy is living through it himself, cleanly, on that reward-flow change he wanted to make this morning. First thing: move the work away from main. Tommy turns to Sam, but for a second he hesitates: what should the branch be called again?

— Sam, I want a separate branch for the change. Does the name matter?

— Git doesn't care, — Sam replies evenly. — But ideally the name should say what the work is. fix-reward is clearer than test123 — you'll remember it yourself in a week. Want me to create it?

— Create it, fix-reward. And work only in it, main don't touch.

● git checkout -b fix-reward
  Switched to a new branch 'fix-reward'

— Done, I'm in fix-reward, — Sam reports. — I'm not touching main.

Tommy checks: yes, he's in the branch, main is untouched. There is now a wall between the working portal and the experiment. And he catches himself realizing that for the first time he is letting Sam into the code calmly.

— Well then, — he says almost cheerfully. — Break it, try it. If you mess up, I'll roll it back. No big deal.

2. Step 2. Change and extra diff

Out of old habit, Tommy gives the task in a single short burst, without overthinking it:

— Sam, something's off with the reward. Figure out the calculation, and just take a look in general so it looks nice.

— I'll clarify, — Sam answers right away. — “Calculation” is reward-flow. And “so it looks nice” is vague. I can pull adjacent areas into that too. Narrow the scope or leave it as is?

Tommy waves it off — the same way he used to a month ago — git is already there:

— Just do it, come on. You'll figure it out as you go.

Exactly what Alex spent all yesterday teaching him out of. Sam doesn't argue and gets to work. He fixes the calculation. And under “make it look nice” he starts tidying up the neighboring area, the leaderboard, which nobody asked him to touch.

But Tommy doesn't rush to accept all the changes. He does what he assembled the whole safe for this morning — before accepting, he opens the changes view:

/diff

And checks with his eyes: is everything here actually from the task?

  reward-flow.js
+   const reward = base * multiplier;    // this is on point — the reward calculation
  leaderboard.js
+   sortByScore(players);                // ← and where did this come from? I didn't ask for the leaderboard

The calculation is on point. But below, in leaderboard.js, there is a stray line. Tommy frowns for a second — and then remembers Sam's question.

— Sam had warned me, he says out loud. — “Make it look nice” was the leaderboard. He asked, and I brushed it off.

Sam didn't mess up. Sam actually asked honestly. The vague brief messed it up — exactly the thing Alex had been hammering into him for a month. The attempt is crooked, so we don't keep this attempt. Good thing he checked /diff before accepting instead of merging blindly.

3. Step 3–4. Reset to a clean point and save with a commit

Tommy doesn't go in and clean things line by line. Since the attempt is crooked, he resets the branch to the last saved point, to the clean one he set up this morning. He asks in words:

Reset the branch to the last saved point; let's start over.

And then Sam, without waiting for the go-ahead, jumps in on his own:

— Stop, for the record. You're asking for git reset --hard — it wipes uncommitted changes without asking, and there will be no way to bring them back. Everything I changed and didn't commit will disappear. That's what you want, right?

— That's exactly what I want, Tommy nods. — Wipe it.

— Understood. One more nuance: if I created a completely new file along the way that git hasn't seen yet, the reset won't touch it — it will stay there. Don't panic, we'll remove it later.

● git reset --hard HEAD
  HEAD is now at a1b2c3d working portal before changes

The terminal prints exactly what he expected: the branch is at the point “working portal before changes”. Which means the disk should now hold a clean state — the correct calculation and the extra tail in the leaderboard erased in one operation, the files back to how they were before Sam. It should. He should check.

And then, a second before he looks at the result, it scratches at him. That night. He had already hit the undo button — sure it would save him — but it didn't reach. The agent had already processed the reset, and Tommy hesitates to open the portal, and there is a short chill in his stomach: what if this thing is the same. What if he looks now — and it's still broken.

He looks.

Clean. Not a single trace. The neighboring area that Sam touched is in place, whole. All the mess, everything he had done, is gone without a trace. Not “almost cleaned up,” not “seems cleaned.” As if Sam had never been here at all.

— Whoa, — Tommy says aloud to the empty room. And once more, quieter: — Whoa.

One command. One second. That's exactly what he had been missing that night. Back then he had spent hours digging out the irreversible by hand — and there was nowhere to rewind to, not a single point behind him. But now there is a point, and rolling back to it is not a feat, not archaeology, not “well, I kind of remember how it was.” You click calmly — and you return. The grown-up version of that same button he had slammed uselessly that night. Only this one reached.

Now the final pass. And this time Tommy phrases it differently — narrowly, precisely, the way he's been taught:

— Sam, only reward-flow, only the calculation. Don't touch the leaderboard or neighboring areas at all.

— Now that's a different conversation, — Sam replies. — The boundaries are clear, I won't have to guess.

It goes as it should. Tommy looks at /diff again — only reward-flow.js, nothing extra. He accepts it. And to lock in the good state, he asks to save the point:

Lock in the change: reward calculation in reward-flow.
● git commit -m "fix: reward calculation in reward-flow"
  [fix-reward e4f5g6h] fix: reward calculation in reward-flow

Now on disk, in the project's history, there is a new honest point — one you can always return to, whether after a closed session or in a week. main stayed clean the whole time: the entire mistake lived and died inside the branch, never reaching the working portal for even a second.

4. Reversible path and verification

Tommy writes down in EVIDENCE_LOG what the day produced. Alex, still speaking under his breath, looks over his shoulder.

— Look at that, — he notes. — Before, what did you write here? Only victories: this worked. And today you have the whole failure laid out on the shelves.

— Well, yes, Tommy skims his own note. — Here is the fix-reward branch and the clean point before changes. Here is the crooked attempt, where Sam caught extra stuff, and the /diff that caught it. Here is the reset — the crooked part erased. Here is the commit for the successful pass. And main, which didn't budge all day.

— Exactly. — Alex perks up a little. — For the first time, not only success has been recorded, but also a safe failure: how the attempt fell apart and how the project survived it without a single scratch. That reversibility I made you prove this morning even on paper — there it is, proven in practice. Let's do a quick check now and make sure you've got everything. Answer me.

He runs through it point by point, like a checklist:

— The work was done in the fix-reward branch, not directly on main?

— Yes.

— Before accepting, did you look at /diff to see what the agent had changed?

— I did, and that's how I caught the extra stuff.

— You rolled back the crooked attempt by resetting the branch, instead of digging it out by hand?

— By reset. In one operation.

— Final pass saved as a commit, point in place? main untouched for the whole cycle? And git was driven by the agent itself, not by commands you typed by hand?

— In place. Untouched. I didn't type a single command by hand, — Tommy counts on his fingers. — Everything matches.

— There you go, — Alex nods. — You put it together the right way. The change was accepted through a branch and a rollback, the crooked part disappeared without surgery, main is clean.

Tommy leans back and exhales. No fireworks in his chest, no rush like from a new toy — just something even, heavy, as if for the first time he has stood on solid ground.

— Sam, — he says in the chat. — Should I create a branch for the next task right away?

— Create it, — Sam replies. — I'm ready to try.

— Then go ahead and try. — Tommy smirks, looking at the clean portal. — Now you can. Not because you got smarter — you're the same as before. But because I got smarter, and now there's a floor under me. If I fall, I'll get back up.

1
Task
Claude Code SELF, level 13, lesson 4
Locked
Safe failure log 📓
Safe failure log 📓
1
Task
Claude Code SELF, level 13, lesson 4
Locked
Broken attempt — do not clean it up, roll it back 🧨
Broken attempt — do not clean it up, roll it back 🧨
1
Task
Claude Code SELF, level 13, lesson 4
Locked
Live run: branch → change → rollback 🎯
Live run: branch → change → rollback 🎯
1
Task
Claude Code SELF, level 13, lesson 4
Locked
Broke it → rolled it back → like it never happened 💥
Broke it → rolled it back → like it never happened 💥
1
Survey/quiz
Version control with git in Claude Code, 13 level, 4 lesson
Unavailable
Version control with git in Claude Code
Version control with git in Claude Code: branches, commits, rollbacks and the three safety nets
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION