0%

useful-commands-all-in-one

VSCode

  1. Ctrl + P - Search by file name
  2. Ctrl + Shift + P - Open command palette
  3. Alt + Left Arrow - Go back
  4. Ctrl + K, Ctrl + 0 - Fold all
  5. Ctrl + K, Ctrl + J - Unfold all

Angular

Create project with specific version

The following command create angular app with angular 15

1
npx @angular/cli@15 new my-app

Git

Branch

1. merge main branch to current branch

This is very useful when you work on a branch for a long time, and every day before you start coding, you sync your branch with main branch.
Suppose you are on the feature-branch branch, and you want to merge the main branch to the feature-branch branch, just use the following command.

1
git pull origin main

Move changes from one branch to another

Suppose you made some modifications on branch A, and you want to move these changes to branch B, you can use the following command.
If branch B is existing and has the latest code, you can use the following command.

1
git switch B # the modification code will automatically bring to branch B

If branch B is not existing, you can use the following command.

1
2
3
4
5
git stash # save the changes
git checkout main # switch to main branch
git pull # pull the latest code
git checkout -b B # create a new branch B
git stash pop # apply the changes to branch B

git checkout vs git switch?

Checkout a remote branch

For single remote, use the following command.

  1. git fetch – fetch the remote branch
  2. git checkout -b local-branch-name origin/remote-branch-name – checkout the remote branch
  3. git switch -t remote-branch-name – switch to the remote branch, use sgit branch -v -a to make sure your branch is ready.
  4. checkout from tag: git checkout tags/v1.0.0 -b branch-name

Delete branch

  1. git branch -d branch-name – delete a local branch
  2. git branch -D branch-name – force delete a local branch
  3. git push origin --delete branch-name – delete a remote branch

Diff

Diff staged/indexed changes

  1. git diff --cached
  2. git status -v – show the changes in the index(staged changes)

2. checkout remote branch

Before checking out a remote branch, you need to fetch the remote branch first.

1
2
git fetch
git checkout -b local-branch-name origin/remote-branch-name

3. Checkout a specific commit.

The following command will create a new branch from the specific commit, you can find the commit id by git log command or from the git history.

1
git checkout -b new_branch commit-hash

Undo

1. Undo last commit

  1. git reset --soft HEAD~1 // undo the last commit and keep the changes in working directory.
  2. git reset --hard HEAD~1 // undo the last commit and remove all changes.

2. Undo staged changes(not committed yet)

  1. git reset HEAD file-name // unstage a file
  2. git reset HEAD . // unstage all files

3. Undo unstaged changes(changes are not added or committed)

  1. git checkout -- . // undo all changes in the working directory, same as git checkout .?
  2. git checkout -- file-name // undo changes in a specific file
  3. git checkout -- '*.js' // undo changes in all js files

4. Undo untracked files

  1. git clean -f // remove untracked files
  2. git clean -f -d // remove untracked files and directories

git restoregit reset的区别是什么?

Stash

git stash – save the changes
git stash list – list all stashes
git stash apply "stash@{n}" – apply the nth stash
git stash apply n – apply the nth stash
git stash pop – apply the latest stash and remove it from the stash list

Chrome

  1. F12 - Open developer tools
  2. Ctrl + Shift + P - Open command palette(only works after you open developer tools)
  3. Ctrl + P - Open file(after you open developer tools), this is pretty useful when you want to find a file in the source tab.
  4. Ctrl + Mouse Left Click - Open a link in a new tab. (also can use Mouse Wheel click)

Yarn

  1. Input chrome://settings in the address bar to open the settings page.

Jest

  1. jest - Run all test
  2. jest --coverage - Run test with coverage report
  3. jest --watch - Run test in watch mode
  4. jest test.spec.ts - Run a specific test file
  5. jest test.spec.ts --coverage - Run a specific test file with coverage report

Windows

Win + Shift + S - Take a screenshot

Reference