Git disasters · Chapter 11 of 14
Re-merging a reverted branch
Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Merges and detective work
- 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: find the revert that hides the first half
Bunty merged the finished new-checkout into main and pushed. But checkout/cart.js and checkout/upi.js are not on main, and the checkout test fails. Find the commit that hides them.
1. Run node --test and list the checkout folder. Two files are missing.
2. Show the history as a graph. new-checkout was merged twice.
3. Find the commit between the two merges that reverted the first merge.
4. Write its hash into answer.txt, in the case's folder.
To pass: answer.txt has the hash of that revert commit (7 characters or more), and no other hash.
- Task 2
Fix: bring the first half back on GitHub
Bring the missing files back on GitHub's main, with a new commit. Do not change main's old commits.
1. Make a new commit that undoes the revert you found.
2. List the checkout folder and run node --test. All tests must pass.
3. Push main to GitHub. Use a normal push, not a force push.
To pass: on GitHub, main's checkout folder is exactly the same as new-checkout's (cart.js, upi.js, card.js and the test). node --test passes on GitHub's main. GitHub's main still has Bunty's second merge.
- Task 3
Guard it: no push while the tests fail
Stop the next push that breaks the tests.
1. Write a hook script in .git/hooks/pre-push.
2. It runs node --test. When the tests fail, it stops the push.
3. When the tests pass, it lets the push through.
4. Make the file executable.
To pass: do task 2 first, so the tests on GitHub's main pass. The Check then tries your hook in a copy of your repository, on main. It commits a failing test and pushes. That commit must not reach GitHub. Then it commits a passing test and pushes. That push must work.
What you will learn
- See what happened: find the revert that hides the first half
- Fix: bring the first half back on GitHub
- Guard it: no push while the tests fail
More in Merges and detective work
Build "Re-merging a reverted branch" 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.