Git without fear · Chapter 5 of 28
Fixed stuff
By the end of this chapter you can write a commit message that says what changed and why, and reword the last commit before you push it. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Day one
- 4 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
Kabir reads the history, newest first, and stops at the top:
git log --format=%s
fixed stuff
Add the order total
Add the menu and prices
"Bunty. Which stuff?" Bunty thinks hard. "The... important stuff?" In six months nobody will remember, Bunty included, and git log --oneline, the view everyone reads, shows nothing but that subject.
A new commit saying "explain fixed stuff" would leave the bad message in the history forever. Amending with --reset-author, as in chapter 1, would fix the message but take the credit away from Bunty. You want the same commit, by Bunty, with a better message.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Write a subject that says what changed
Bunty's last commit says fixed stuff. Give it a subject that says what changed.
1. Run git show --stat to see what the commit changed.
2. Change the last commit's message with git commit --amend -m. It is not pushed, so this is safe.
3. Write the subject as a short command, for example Fix the ... price.
To pass: the subject names the bun maska or the price. It is 50 characters or fewer, starts with a capital letter and has no full stop at the end. A vague subject like fixed stuff, update or misc does not count.
- Task 2
Add a body that says why
A good message also says why the change was needed.
1. Change the message again with git commit --amend.
2. Give two -m options: the first is the subject, the second is the body.
3. Run git log -1 to see the whole message.
To pass: the last commit's message has the subject, then a blank line, then a body of at least 10 characters that says why.
- Task 3
Keep the change, the parent and the author
Changing the message must not change anything else about Bunty's commit.
1. Run git status first. Nothing should be staged, or it goes into the commit too.
2. Do not use --reset-author. Bunty stays the author.
3. Do not push, and do not make a new commit.
To pass: the commit's author is still Bunty <bunty@tapri.in>. It changes only prices.csv, which has Bun maska,50. It sits right on top of Add the order total, the commit GitHub's main has. It is the only commit that is not pushed.
- Task 4 · interview question
Interview: amend makes a new commit
Interview question: does amend edit the old commit, or make a new one? Show the answer with the old commit's hash.
1. The old fixed stuff commit still exists, with its own hash.
2. Save its hash before you change the message. Or find it later with git reflog.
3. Save the hash in answer.txt, in the chapter folder.
To pass: answer.txt has the hash of the old fixed stuff commit, at least 7 characters long.
What you will learn
- A good message: a short subject that says what changed, a blank line, then a body that says why.
- git commit --amend -m: reword the last commit, before it is pushed. Two -m give a subject and a body.
- Amend makes a new commit: the old one gets a new hash, and git reflog still remembers it.
More in Day one
Build "Fixed stuff" 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.