Git without fear · Chapter 6 of 28
Reading the history
By the end of this chapter you can search a project's history for the commit that changed a line, and give that commit a name. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Day one
- 3 tasks
- Git
- In the all labs plan
The first 2 chapters of Git without fear are free. This one comes with the all labs plan.
Why you need this
A customer waves the menu at Ravi: "Fifty-two rupees for a cutting chai?" Ravi raised it to 25 last week, not 52. Somebody swapped two digits, and Meera wants to know which commit did it, who made it and when, so the fix goes in the right place and nobody gets blamed by guesswork.
So far you know git log, which lists messages. No message here says "cutting chai to 52", so the log alone points nowhere. You could open every commit with git show and read each diff, which works for seven commits and not for the thousand a real project has. Git can search the changes for you.
What you build: 3 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Find who changed the cutting chai line
Cutting chai is 52 rupees on the menu. Find the commit that made it 52. The commit messages do not help.
1. Run git blame on menu.txt. It shows the commit that last changed each line.
2. Or search the changes with git log and the -S option, with the text in quotes.
3. Note the short hash of the commit you find.
To pass: you ran git blame, or git log with -S, -G, -L or -p, in the chapter folder. A command with a typing mistake does not count, so type it again.
- Task 2
Tag the commit that broke the price
Put a name on the commit that broke the price, so the team can find it.
1. Run git show with the hash you found. Check that its diff turns Cutting chai 25 into Cutting chai 52.
2. Make a tag called price-bug on that commit. Give git tag the hash too.
3. Run git log --oneline --decorate to see where the tag is.
To pass: the tag price-bug is on the commit that changed Cutting chai 25 to Cutting chai 52 in menu.txt. Not the newest commit, and not a later commit that only kept the line.
- Task 3 · interview question
Interview: what HEAD points to
Interview question: what does HEAD point to right now?
1. Run git log --oneline --decorate. Look for HEAD and its arrow on the top line.
2. Or print the file .git/HEAD with cat.
3. Save the name of the branch HEAD points to in answer.txt, in the chapter folder.
To pass: answer.txt has the name of the branch you are on, or the hash of the commit HEAD is on.
What you will learn
- git log with who and when: the history as a list of suspects.
- git blame: every line of a file, with the commit that last changed it.
- git log -S: the commits that added or removed a piece of text.
- Tags and HEAD: a name you give a commit, and the name Git gives the place you are now.
More in Day one
Build "Reading the history" yourself
Your first week on Tapri’s team, and every Git situation it throws at you. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Git without fear are free. This one comes with the all labs plan.