I built myself a little utility 'function' for locally browsing Casey's code changes with git that I thought I'd share with you. I've also added the thought process for anyone interested in how/why it works.
TL;DR:
Usage:
| git day 211 # show changes made on day 211
git days 200 211 # show changes made from 200 to 211
git day 211 --name-status # you can still use flags for diff;
# here, show only the status of file changes (not code changes)
|
Implementation: add these aliases to git
| [alias]
day = "! git show day$1:day.txt && git difftool day$1^ day$1 ${@:2} -- :!/:day.txt #"
days = "! git show day$1:day.txt day$2:day.txt && git difftool day$1 day$2 ${@:3} -- :!/:day.txt #"
|
- First off, I'm assuming that you have access to the github repo. If not, go preorder the game, you monstar!
- If you clone the cpp repo, you notice that all of the commits have tags in the form `day###`, so we can get use `git diff day210 day211` to get the changes for day 211. Much easier than comparing commit SHAs!
We can also use the `^` operator, which goes to the commit's 'parent': `git diff day211^ day211`.
- This gets a bit cumbersome if you're using it a lot. Git aliases to the rescue!
| day = "!git difftool day$1^ day$1 #
|
- `!` lets us treat the subsequent alias text as a shell command.
- You can use `diff` instead of difftool if you prefer, but this lets me compare both versions with vimdiff.
- Any text following the invocation of the alias is both treated as a parameter and appended to the end. The `#` comments out everything at the end, preventing the unwanting append.
- This cuts down some typing, but we'd still like to be able to use flags for difftool: `${@:2}` is replaced by all parameters from the second one (we don't want to repeat the first).
- Not bad, but could I get a bit more contextual info about what happened on the day(s) I'm looking at?
Yes, as it turns out. Because the title for the episode is given in `day.txt`, we can use `git show day$1:day.txt` to cat the file before doing anything else.
- We don't really need to see that `day.txt` has been changed though - it always has been - and it just gets in the way when it diffs the contents. We can exclude it from the comparison with `-- :!/:day.txt`.
Hopefully this is helpful for someone - I find it faster than browsing the github site, and I like having the files local to my machine.
P.S. This is a more general vimdiff/difftool thing: the one thing I haven't yet taken the time to figure out is how to open up all commit comparisons at once in vim (e.g. in different tabs). Currently it opens the first, then when you close it, it moves onto the second, etc, so it's a bit awkward if you want to go back. You can probably do something with a bunch of temp files of all the comparisons... If anyone works it out, I'd be happy to hear about it.