margareta.dev

TIL #13

#git 2021-10-02

Git alias to rewrite username or email:

git config --global alias.change-commits '!'"f() { VAR=\$1; OLD=\$2; NEW=\$3; shift 3; git filter-branch -f --env-filter \"if [[ \\\"\$\`echo \$VAR\`\\\" = '\$OLD' ]]; then export \$VAR='\$NEW'; fi\" \$@; }; f"

Usage:

git change-commits GIT_AUTHOR_EMAIL "wrong@email.com" "right@email.com" HEAD~3..HEAD

TIL #12

#cmd, #linux 2021-08-19

Check history of commands in linux using history. Search the history with Ctrl + R.

TIL #11

#git, 2021-08-12

Get list of file changes between two branches in git:

git diff --summary origin/master origin/feature-branch

Shows rename/move information one file per line

git diff --name-only origin/master origin/feature-branch

Shows list of files that changed.

TIL #10

#cmd, #linux 2021-07-23

Command to search for files and folders in linux by name:

sudo find / -name filebeat.yml

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.

Examples:

  • 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={state.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