golang

Basic Commands

  • Restore file git restore file_path
  • Rename or move: git mv file_path new_name_or_path
  • Log git log —oneline —graph —decorate
    • Last 3 days —since=“3 days ago”
    • Follow renamed file —follow
    • Log a file — file/path
  • Check a commit git show commit_id
  • Alias git git config —global alias.hist “log —all —oneline —graph —decorate”
    Now we can use git hist
  • Compare commit git diff old_commit HEAD
    • HEAD^ is commit prior to HEAD
  • Compare local to remote git diff master origin/master

Continuous Deploy

# This is a basic workflow to help you get started with Actions

name: CD

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      - name: Setup Node.js environment
        uses: actions/setup-node@v2.1.5

      - name: Install dependencies
        run: npm ci

      - name: Generate
        run: npm run build:docs

      - name: Deploy to GH Pages
        run: |
          git config --global user.email ${{secrets.GIT_EMAIL}}
          git config --global user.name ${{secrets.GIT_USERNAME}}
          git remote set-url origin https://${{secrets.GIT_TOKEN}}@github.com/xiaosasori/my-vue-components.git
          npm run deploy

Change commited username, user email

# Change the author name and/or email of a single commit.
#
# change-author [-f] commit-to-change [branch-to-rewrite [new-name [new-email]]]
#
#     If -f is supplied it is passed to "git filter-branch".
#
#     If <branch-to-rewrite> is not provided or is empty HEAD will be used.
#     Use "--all" or a space separated list (e.g. "master next") to rewrite
#     multiple branches.
#
#     If <new-name> (or <new-email>) is not provided or is empty, the normal
#     user.name (user.email) Git configuration value will be used.
#      sh bin.sh main d6df2fd

force=''
if test "x$1" = "x-f"; then
    force='-f'
    shift
fi

die() {
    printf '%s\n' "$@"
    exit 128
}
targ="$(git rev-parse --verify "$1" 2>/dev/null)" || die "$1 is not a commit"
br="${2:-HEAD}"

TARG_COMMIT="$targ"
TARG_NAME="${3-}"
TARG_EMAIL="${4-}"
export TARG_COMMIT TARG_NAME TARG_EMAIL

filt='

    if test "$GIT_COMMIT" = "$TARG_COMMIT"; then
        if test -n "$TARG_EMAIL"; then
            GIT_AUTHOR_EMAIL="$TARG_EMAIL"
            export GIT_AUTHOR_EMAIL
        else
            unset GIT_AUTHOR_EMAIL
        fi
        if test -n "$TARG_NAME"; then
            GIT_AUTHOR_NAME="$TARG_NAME"
            export GIT_AUTHOR_NAME
        else
            unset GIT_AUTHOR_NAME
        fi
    fi

'

git filter-branch $force --env-filter "$filt" -- $br

#!/bin/sh

git filter-branch -f --env-filter '

OLD_EMAIL="leon.minhanh@gmail.com"
CORRECT_NAME="xiaosasori"
CORRECT_EMAIL="xiaosasori@gmail.com"

if [ "$GIT_COMMITTER_NAME" = "leonanhnm" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_NAME" = "leonanhnm" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags