More in Git
Recover a branch you deleted
Git
The reflog remembers where HEAD has been for about ninety days, so a deleted branch is almost never really gone.
Search the whole history for a string
Git
Finds every commit whose diff added or removed a piece of text, including in files long since deleted.
Stop tracking a file without deleting it
Git
For the config file that should never have been committed. Add it to .gitignore afterwards.
List branches merged into main
Git
Finds the branches that are safe to delete, and the ones that are not.
Find the commit that introduced a bug
Git
Binary search across history. Mark a known good and a known bad commit and git narrows it down for you.
Show what a merge will do before doing it
Git
Lists the commits and the files a merge would bring in, so a surprise is less likely.
Undo the last commit but keep the changes
Git
Moves HEAD back one commit and leaves everything staged, which is what you usually want after committing too early.
Random picks
Exhaustiveness check on a switch
TypeScript
Assigning to never makes the compiler fail the build when a new union member is added and left unhandled.
Records and pattern matching in Java
Systems
A record plus a switch pattern removes most of the ceremony this used to take.
Merge dictionaries
Python
The | operator returns a new dict; |= updates in place. Later keys win in both.
Generate a strong random secret
Security
For session keys and tokens. Never reach for a password generator or a UUID for this.
A Makefile that documents itself
Build & CI
Running make with no arguments prints every target that carries a comment.
Read a file into a string in Go
Systems
os.ReadFile replaced ioutil.ReadFile in 1.16 and is the one-liner for small files.
Check a file's checksum
Security
Verifies a download actually matches what the publisher signed, rather than trusting the transfer.
Inspect a TLS certificate from the command line
Networking
Prints the subject, issuer and validity dates without opening a browser.