Git points north

Time:2021-11-18

install

  • window Git Download
  • Linux executionsudo apt-get install git

    //After installation, you need to configure it on the command line
    git config --global user.name "Your Name"
    git config --global user.email "[email protected]"

    Basic concepts

    The GIT project has three phases

  • Working directory: local file directory
  • Staging areas: File snapshot areas that have been modified and add committed
  • Git Repository: Hidden directory. Git

    The basic git workflow is as follows

  • Modify the file in the workspace.
  • Selectively stage the changes you want to commit next time, which will only add the changed parts to the staging area.
  • Commit the update, find the file in the staging area, and permanently store the snapshot in the GIT directory.

Common commands

Git init // create warehouse
Git add < File > // add files to the staging area

Git limit - M "commit messages" // submit all contents of the staging area to the current branch
Git log // view the submission log -- pretty = oneline parameter
Git log -- graph -- pretty = oneline -- abrev commit // view the simple submission information
Git reflog // view the command history
Git status // view the current status
Git reset head < File > // version fallback head represents the current version

Git checkout < name > // switch branches 
Git checkout -- < File > // return to the state of the last git commit or git add
Git checkout - B < branch name > origin / < branch name > // create a branch corresponding to a remote branch locally
Git restart < File > // undo the file from the staging area 
Git RM -- < File > // delete the file

Git branch // view branches
Git branch - A // view all remote branches
Git branch < name > // create a branch
Git branch - d < name > // delete branch
Git branch -- set upstream to = origin / < branch name > < branch name > // specify the link between the local branch and the remote branch

Git switch < name > // switch branches (recommended)

Git merge < name > // merge a branch to the current --no-ff to retain the branch information

Git cherry pick < commit > // copy and submit to the current branch

Git stash // save the current work content
Git stash list // save the list
Git stash apply // restore the saved contents without deleting them
Git stash apply stash @{0} // restore the specified version
Git stash drop // delete the saved content
Git stash pop // restore and delete the saved content at the same time
Git reset // fallback branch records
Git revert // undo the changes and share them with others



Git remote - V // view remote library information
Git pull // pull the remote code to the local
Git push origin < branch name > // push local code to remote

Associated remote warehouse

  • Get the local SSH key and find the. SSH directory in the user’s home directory, which has ID_ RSA and ID_ Rsa.pub two documents, ID_ RSA is the private key and cannot be disclosed. ID_ Rsa.pub is a public key that can be confidently told to anyone. If it does not exist, it can be passed through git basessh-keygen -t rsa -C "[email protected]" establish
  • GitHub create repository
//1. Associated remote warehouse
git remote add origin <address>
//2 push to remote warehouse -u associate local master and remote master
git push -u origin master