TIL #9

#git, 2020-09-25

Difference between HEAD~ and HEAD^. branch-name~ is used to go back a number of commits from the tip of the branch, while branch-name^ is used to choose a parent of the tip of the branch, which only makes sense if there was a merge and the commit has several parents.


  • HEAD~3 (go 3 commits back from the current commit) is the same as HEAD^^^ (parent of parent of parent),
  • HEAD^2 means the second parent of the current commit, which is rarely needed,
  • HEAD~ is the same as HEAD~1 and HEAD^ is the same as HEAD^1.
  • undo the last commit:
git reset HEAD~

TIL #8

#git, 2020-06-26

Get the name of the current branch in git:

git rev-parse --abbrev-ref HEAD

TIL #7

#dev-ops, #docker, 2020-06-22

Kill the process locking a port on Mac:

$ sudo lsof -i tcp:3000
$ kill -p PID

TIL #6

#dev-ops, #docker, 2020-06-14

You can reload nginx configuration inside your docker container without restarting the whole container, source. Find the id of your nginx container and send reload signal to it:

$ docker ps
# check whether the configuration is valid
$ docker container exec <container> nginx -t
$ docker container exec <container> nginx -s reload

TIL #5

#dev-ops, #docker, 2020-06-14

Difference between docker-compose restart and docker-compose up: up builds, recreates and starts the containers. Typically, you want docker-compose up since restart will not recreate them so any changes made to docker-compose.yaml are not going to be picked up.


TIL #4

#typescript, #react, 2020-06-12

Tagged union can help avoid invalid states, e.g. passing nullable id when in fact it can never be null:

type State = { status: "Empty" } | { status: "SelectedProject"; id: number }

const App = () => {
  return state.status === "Empty" ? (
    <NoProjectsAvailable />
  ) : (
    <SelectedProject id={} />

TIL #3

#git, 2020-06-12

You can cherry-pick only some specific changes in a commit in git:

git cherry-pick -n <commit_hash>
# the changes appear as staged
# unstage/modify/stage
git commit -m "Fix stuff"

You can inspect and modify the result and then commit. Awesome!

TIL #2

#gatsby, #react, 2020-06-11

Filenames in gatsby must be lowercased, otherwise the page will become blank in production builds. It is a convention in gatsby since the casing of filename maps directly to the rendered file.


TIL #1

#git, #windows, 2020-06-10

Rename case-only directory on Windows in a git repo:

$ git mv docs DocsS2
$ git mv Docs2 Docs