Skip to main content

Purge Your Advent of Code Inputs and Get Off the Naughty List

·3 mins· loading · loading · ·
Advent-of-Code Git Github
Table of Contents
Now you won’t get coal in your stocking, guaranteed!
NelsonDane/advent-of-code

My Advent of Code Solutions, in a Different Language Every Year!

Python
3
0

Introduction
#

Advent of Code is a wonderful way to spend the holidays helping virtual elves solve puzzles instead of spending time with your family. However, during this season of giving and sharing, there’s one thing you should keep to yourself: your unique puzzle inputs. This is something I (and many others) didn’t know when I first started participating in Advent of Code, so my git history was littered with my unique inputs. That’s an easy way to end up on Santa’s (or Eric’s) naughty list.

...If you're posting a code repository somewhere, please don't include parts of Advent of Code like the puzzle text or your inputs. - Advent of Code Legal Notice

...No content at adventofcode.com (including the inputs) is licensed for reproduction or distribution without permission from Advent of Code. - r/adventofcode

The Solution
#

Unfortunately, I didn’t realize at the time that storing your inputs online was wrong. I happily pushed my solutions, inputs and all, to my GitHub, then went on my merry (christmas) way. It was years later that I started following the Advent of Code subreddit and saw the warnings about sharing your inputs. The option I immediately thought of was to just nuke the repository and start fresh. But what about the stars I had gotten from my friends, or my long commit history? There has to be a better way!

And there was.

We’re gonna rewrite history like Jack Frost in The Santa Clause 3: The Escape Clause

Fortunately for us, we don’t need a magic snow globe to fix this. We can use the git filter-branch command to rewrite our git history and remove the text files containing our inputs. This command is a bit dangerous, so make a backup of the repository before you start. However, it isn’t as dangerous as angering an ancient man who watches you while you sleep.

git filter-branch --tree-filter 'rm -f */*/input.txt' HEAD

You might need to adjust the rm -f */*/input.txt part of the command to match the path of your input files. For me, all my inputs were named input.txt and were two directories deep (e.g. 2023/day1/input.txt). If you have a different naming scheme, you’ll need to adjust the command accordingly. If you want to see what files are picked up by the glob, you can run ls */*/input.txt to see the list of files that will be removed.

You did it! You rewrote history to the way it should’ve been. Now all that’s left is to force push the changes to your remote repository. This will overwrite the history on the remote repository with your new, nice history. It was as if Jack Frost had never upt on the hat and coat to become Santa Claus to begin with.

Conclusion
#

Now you can rest easy knowing that you won’t be getting coal in your stocking this year. Just be sure to add input.txt to your .gitignore before next year, otherwise you’ll be back on the naughty list like Buddy’s dad:

You see, Buddy, he’s on the naughty list.

Related

Enabling Automatic Updates on NixOS Doesn't Have to Be Hard
·7 mins· loading · loading
Nixos Github-Actions Systemd Github Automation Cluster
Contributing to Foss Doesn't Have to Be Hard
·5 mins· loading · loading
Foss Open-Source Contributing Github Hi.events