Technology Sharing

Git Review

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Basic process

  • Workspace–>Staging Area–>Local Warehouse–>Remote Warehouse

basic configuration

  • git config user.name [username]

    1. Set Username
    2. Add –project to take effect for the current project (default)
    3. Add –global to take effect for the current user (example: git config --global user.name [user name])
    4. Add --system to take effect for all users and projects
    5. Add –get retrieval settings to verify whether the settings are successful
  • git config user.email [email]

    1. Set up your mailbox
    2. Add –project to take effect for the current project (default)
    3. Add --global to take effect for the current user (example: git config --global user.email [username])
    4. Add --system to take effect for all users and projects
    5. Add –get retrieval settings to verify whether the settings are successful

Common naming

  • git init

    Initialize git repository

  • git add

    1. Add [file1] [file2] parameters to add one or more files in the workspace to the cache
    2. Add the [file] parameter to add the specified file in the workspace to the cache
    3. Add the . parameter to add all files in the current directory of the workspace to the cache
  • git status

    View the current status of the repository and display the files that have changed

  • git commit

    1. Add the -m parameter, msg is the comment information, submit the files in the temporary storage area to the local warehouse
    2. Add the -a parameter, and you don't need to execute git add. You can directly submit the tracked and modified files to the local repository.
    3. Add –amend to modify the last submission record
  • git push

    1. Add -u origin [branch name], use -u for the first commit and push directly using git push
    2. Add –set-upstream origin [branch name] to link the remote repository (mandatory method)
  • git log

    1. View submission record information
    2. Add the --oneline parameter, git log information becomes very concise
  • git ls-files

    View local warehouse files

  • git reset

    1. Add the --hard parameter to reset all regions (excluding remote repositories) directly to the target version (default)

      You can use git push -f to force push later.

    2. Add the –soft parameter to reset the files from the local repository to the staging area

    3. Add the --mixed parameter to reset the files from the local repository to the workspace

  • git restore --staged/–cached

    Reset files from the staging area to the working area

  • git rm

    1. Delete from git repository (add a deletion record and untrack the file)
    2. Add the --cached parameter to delete the corresponding file from the cache
  • git branch

    1. View git branch
    2. Add parameters and create a new branch
  • git checkout/switch

    1. Add parameters and switch branches
    2. Add the -b parameter to create a new branch and switch branches
    3. Add the -d parameter to delete the branch (unmerged branches cannot be deleted)
    4. Add -D parameter to delete branches (can delete unmerged branches)
  • git diff

    1. Directly compare the staging area and the working area
    2. Add the --cached parameter to compare the staging area and the local warehouse
    3. Add / parameter to compare local repository and workspace
    4. Add parameters and compare two branches
  • git merge/rebase

    Merge branches (manually resolve conflicts)

  • git pull

    Equivalent to git fetch + git merge to obtain the remote warehouse address file and merge the local warehouse branch

  • git remote

    1. Add the add origin parameter to add the remote repository address
    2. Add the -v parameter to view the remote address
  • git clone

    1. Copy remote warehouse files to local warehouse
    2. Add -b: select the branch name to copy the remote repository file to the local repository
  • git stash

    1. Temporarily save to local, not upload to server
    2. Add the save [msg] parameter and add some comments
    3. Add the pop parameter to restore the latest progress to the workspace
    4. Commonly used: git stash->git pull->git stash pop
  • git tag

    Tagging

  • git revert

    Rollback, reset the corresponding submitted operation

Development commit naming convention

The relevant git commit -m commit naming convention isNamed Types

  • feat: new function
  • fix: fix a bug
  • docs: documentation changes
  • style: code format changes (changes that do not affect code operation), note that this is not a CSS modification
  • refactor: refactoring (code changes that are neither adding new features nor fixing bugs)
  • perf: Code changes to improve performance
  • test: add test
  • build: changes that affect the build system or external dependencies (example scope: gulp, broccoli, npm)
  • ci: Changes to ci configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • revert: restore the previous commit (rollback)
  • chore: Changes to the build process or supporting tools
  • footer: some notes, usually a link to a breaking change or bug fix