2020年5月21日 星期四

[Linux & cli] Useful Linux command

Details
The following are some useful commands which usually made use and always being forgotten when needed, here is a note down.
  • Edit /etc/fstab to mount new drives (files system, mount point, type, options, dump, pass)
    • /dev/sdb1   /home/jacky/Documents/2tb-hdd   ext4   defaults  0   0
    • mount -av (run from root, show the mount point)
  • Run command and pipe all output to file
    • do_something 2>&1 | tee -a some_file (2>&1 is to direct all stderr to stdout)
  • Clear all text in a text file
    • > someTxtFile.txt
  • Kill process occupied by a known port (e.g. 32769)
    • sudo kill -9 $(sudo lsof -t -i:32769)
References

2020年5月20日 星期三

[Chrome & Debug] Create and debug with test snippets in Chrome

Background
Very often it would be convenient and time consuming to have a fast setup and runnable js snippet playground to quickly test for the logic or debug etc.

Solutions
1. Open chrome
2. Right click "inspect" or press F12 shortcut
3. Navigate to "Sources"
4. At the left hand side panel, click the double right arrow, click "New snippet"
5. A snippet panel pops and you can freely write the test code
6. Press "Ctrl + Enter" to execute 

2020年5月14日 星期四

Frequently used git command

Details
There are some cases I need to use some specific git commands for some special purposes, like 
  • Undoing git merge which haven't be pushed
    • git reflog (Get the commit desired to return)
    • git reset --hard sha

  • Cherry-picking specific file changes from 1 commit to another
    • git checkout <branch or sha of commit> -- filename

  • Retrieve just 1 file from specific branch
    • git checkout experiment -- app.js

  • Show content changes which have been staged
    • git diff --cached

  • Show the diff of the same file between different commits of the same branch
    • git diff HEAD^^ HEAD someFile (Show differences of someFile 2 commits before HEAD)

  • Show file changes on specific commit (without diff information)
    • git show --pretty="" --name-only {commit-sha}

  • Show commits differences between 2 branches since branch created (file list)
    • git log --oneline master..myBranch (Show changes since master branch)
    • git log --oneline --no-merges master..myBranch (Show changes since master branch skipping merge commits)

  • Get a list of branches created ordered with create date
    • git branch --sort=-committerdate  # DESC
    • git branch --sort=committerdate  # ASC

  • Commit with standard input
    • echo -e 'Update version number to v1.6.72.0\n\nfrom v1.6.70.0 to v1.6.72.0' | git commit /home/jacky/Documents/gitproj/p2_controller/docker/docker-compose-prod.yml /home/jacky/Documents/gitproj/p2_controller/docker/docker-compose-prod-upgrade.yml /home/jacky/Documents/gitproj/p2_controller/p2_controller/static_data/VERSION -F -
References