Git disasters · Chapter 8 of 14
A huge file blocks the push
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.
Why you need this
A commit stores a snapshot of every file. Deleting a file in a new commit makes a new snapshot without it, but the old commit still has it, and a push sends every commit the server does not have. On a small site repo:
$ git log --oneline --stat
78180ea Remove the backup
backup.zip | Bin 7000000 -> 0 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
f84a97d Add a backup
backup.zip | Bin 0 -> 7000000 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
08f7694 Start the site
Every object in the history, with its size, tells the same story: the 7 MB blob is still reachable from main.
$ git rev-list --objects main | git cat-file --batch-check='%(objecttype) %(objectsize) %(rest)' | sort -k2 -n | tail -2
commit 226
blob 7000000 backup.zip
git log --diff-filter=A -- <path> shows only the commit that added a path, which is how you find where a big file came in.
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 commit with the video
GitHub refuses Bunty's push because one file is too big. Find the commit that added that file.
1. Run git push in the terminal. Read GitHub's error. It names the file and the size limit.
2. List the commits that GitHub does not have yet, with the files each one changed.
3. Find the one commit that added promo/diwali-promo.mp4.
4. Write its hash into answer.txt, in the case's folder.
To pass: answer.txt has the hash of that commit (7 characters or more), and no other hash.
- Task 2
Recover: push the Diwali work without the video
Push Bunty's Diwali work to GitHub, without the video. Deleting the video in a new commit does not help: the old commit still has it.
1. If you want to keep the video, copy it out of the repository first.
2. Change the three commits that GitHub does not have yet. Take the video out of each one.
3. Keep everything else in those commits, promo/README.md too.
4. Push main to GitHub.
To pass: GitHub's main has Bunty's three commits (Add the Diwali menu, Add the Diwali promo video, Add the Diwali prices), each one only once. GitHub's main still has promo/README.md. No commit on GitHub's main, and no commit on your main, has a file over 5 MB. Your main and GitHub's main are the same commit.
- Task 3
Guard it: stop big files before they are committed
Stop the next big file before it gets into a commit.
1. Write a hook script in .git/hooks/pre-commit.
2. It stops the commit when any staged file is over 5 MB (5,242,880 bytes).
3. It lets every other commit through.
4. Make the file executable.
To pass: the Check tries your hook in a copy of your repository. It adds a 6 MB file with git add -f (so .gitignore does not stop it) and commits. That commit must fail, and HEAD must stay where it was. Then it commits a small file. That commit must work.
What you will learn
- See what happened: find the commit with the video
- Recover: push the Diwali work without the video
- Guard it: stop big files before they are committed
More in Rewriting history
Build "A huge file blocks the push" 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.