Git disasters · Chapter 7 of 14
Commits with the wrong author email
Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Rewriting history
- 3 tasks
- Git
- In the all labs plan
The first 2 chapters of Git disasters are free. This one comes with the all labs plan.
What you build: 3 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
See what happened: count the wrong emails
Some of Bunty's commits on loyalty-app have his personal email, not bunty@tapri.in.
1. Look only at the commits on loyalty-app that are not on main.
2. Print the author email of each of these commits with git log.
3. Count the commits whose email is not bunty@tapri.in.
4. Write only that number into answer.txt in the case's folder.
To pass: answer.txt has the right count, and no other number.
- Task 2
Fix: rewrite the authors on loyalty-app
Rewrite loyalty-app so every commit has Bunty's work email. Nobody else has this branch yet, so a rewrite is safe.
1. Switch to loyalty-app.
2. Rebase it onto main, and amend each commit's author as Git replays it.
3. Check the authors with git log.
4. Push loyalty-app to GitHub.
To pass: every commit on loyalty-app on top of main has the author "Bunty <bunty@tapri.in>", with a capital B. The six commit messages stay the same, in the same order. The files at the end stay exactly the same. main must not change, and GitHub's loyalty-app must match yours.
- Task 3
Guard it: only tapri.in authors
Make Git refuse commits from an email outside tapri.in.
1. Write a hook in .git/hooks/pre-commit. Start it with a line like #!/bin/sh.
2. In the hook, ask Git for the author of the commit it is about to make. Do not read user.email from the config: the author can be set another way.
3. If the author email does not end in @tapri.in, print a reason and exit with 1. Otherwise exit with 0.
4. Make the hook executable.
To pass: the Check tries it in a copy of your repository. A commit authored as someone@example.com must be refused. A commit authored as ravi@tapri.in must go through.
What you will learn
- See what happened: count the wrong emails
- Fix: rewrite the authors on loyalty-app
- Guard it: only tapri.in authors
More in Rewriting history
Build "Commits with the wrong author email" yourself
Bunty is Tapri's new junior developer, and Kabir keeps handing you the Git incidents left behind. Each is a disaster interviews love to ask about. 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 disasters are free. This one comes with the all labs plan.