Code / Command Line & Git / Unit 3: Git basics: save every version

See changes and undo them बदलाव देखें और undo करें

Lesson 8 of 12 · about 12 minutes · git diff shows what changed; git restore throws a change away.

⚡ 0 XP

Step 1 of 2

git diff: spot the difference

git diff compares your files with the last saved version. Lines starting with - were removed; lines starting with + were added.

Always glance at git diff before committing. It catches silly mistakes, like typing ₹100 instead of ₹10!

🎯 Challenge: Price change, checked +15 XP

Someone changed the chai price in menu.txt. Run git diff to see the change (you should see +Masala chai ₹12). It looks right, so stage it and commit with a message that includes the word price, e.g. Update chai price.

Try twice to unlock the solution (0/2)

terminalCtrl ⏎

A safe practice terminal. Type a command and press Enter. Type help to list commands. Tab completes names, ↑ recalls the last command.

Files · ~ = /home/asha
  • chai-site/ ← you are here
  • menu.txtM
Git timeline
mainc3e49a3 Add menuAdd menuHEAD→main
Checklist

Press Run to check your code.

  • You ran git diff
  • The diff showed +Masala chai ₹12
  • A commit message mentions price
  • Working tree is clean
Lesson notes (text version)

1. git diff: spot the difference

git diff compares your files with the last saved version. Lines starting with - were removed; lines starting with + were added.

Always glance at git diff before committing. It catches silly mistakes, like typing ₹100 instead of ₹10!

Challenge: Price change, checked

Someone changed the chai price in menu.txt. Run git diff to see the change (you should see +Masala chai ₹12). It looks right, so stage it and commit with a message that includes the word price, e.g. Update chai price.

2. git restore: the undo button

Messed up a file? If you have not committed the mess, git restore menu.txt brings back the last saved version. It is like Ctrl+Z for your whole file.

It throws your unsaved change away, so use it only when you really want the old version back.

Challenge: Oops! Bring the menu back

A wrong > wiped menu.txt and now it only says "oops". Run git status to see it is modified, then use git restore menu.txt to bring back the committed menu. Check it with cat menu.txt.

Search by task, format or tool name.