General operation flow: Workspace -(staging area – local library)- pull update local – push to remote library

Basic commands

  • Git init Initializes a Git repository

  • Git status Displays the current repository status

  • Git log < id /-1/ -p > git log < id /-1/ -p

  • Git reflog looks at the command history to determine which version to go back to in the future

Two. Add, delete, change and check

  • Git add < files/folders /.> (. Means add all files) to the staging area

  • Git commit -m –amend adds changes to commit to the local library

  • Git rm < file > delete files

  • Git reset Rollback the version

Git reset --hard <commit id >Copy the code
  • Git checkout — Undo the change

    • If the “–” parameter is removed, it represents the “switch branch” function
    • If it is not added to the temporary storage area, cancel it directly.
    • Before committing to the local repository, cancel the add (git reset HEAD) and then undo it.
    • That is, when you add to the staging area and commit to the local library, version rollback is used
  • Git diff < file > to view the changes

  • Git diff HEAD — < file > compare workspace and staging

  • Git diff HEAD –cached < file > comparison of staging and branch local libraries

3. Branch management

HEAD: the latest commit point for the current branch

  • Git show

    Check the related information
  • Git branch Displays branches
  • Git branch creates the BN branch
  • Git branch -d deletes the BN branch
  • Git branch -d force drop bn branch (used to drop a branch that is not merged)
  • git checkout Switch bn branch
    • Git checkout -b creates and switches branches
  • git merge Merge branches to the current branch
    • Git merge –no-ff — m
      • “–no-ff” disables fast mode so that branch history can be viewed.
3.2 Conflicting labeling modes

< < < < < < = = = = = = = > > > > > > > >

3.3 Git Flow Management Policies
  • Master: stable release branch
  • Dev: Development branch
  • Feature: New feature development branch, merged into dev branch after development.
  • Hotfix: Fix emergency bug branch, merge to master and dev after fix.

Iv. Label management

Similar to branch operations

  • Git tag Displays all tags
  • git tag The new label
    • The default is HEAD. You can also specify a commit ID, such as git tag
    • Git tag -a -m “I am description” create a tag with instructions
  • Git push origin — Tags push all tags
  • Git tag -d Deletes a local tag
  • git push origin :refs/tags/Delete a remote label.
    • Tips: You need to delete the local label first

5. Remote warehouse

5.1 Warehouse Related
  • Git remote -v
  • Git clone < repository location > clone a remote repository

Example:

git clone [email protected]:jasonhww/test.git
Copy the code
  • Git remote add < repository name > < repository address > Associate the local repository with a remote repository

Example:

git remote add origin [email protected]: Jasonhww /test.git /* If a local repository needs to be associated with multiple remote repositories, use different names to identify the remote repositories. jasonhww /test.git git remote add gitee [email protected]: jasonhww /test.git git push github master git push gitee masterCopy the code
  • Git remote rm < repository name > remove the remote repository association

Example:

git remote rm origin
Copy the code
5.2 Branch Correlation
  • Git push origin master push master branch to remote library

    • The first commit with the “-u” parameter not only pushes the local branch but also associates the remote branch
  • Git push origin dev pushes the dev branch to the remote library

  • Git pull origin master Fetch the master branch code from the remote repository and merge it locally

  • Git fetch origin master The master branch code from the remote library is fetched locally.

  • Git checkout -b origin/ create a local branch corresponding to the remote branch

  • Git branch –set-upstream origin/ connect local and remote branches

5.3 Rebase
  • The advantage is that the local unpushed fork commit history is organized into a straight line
  • The downside is that the local fork commit has been modified

Vi. Storage operation

  • Git stash stash (all code in the current branch that is not committed is stored temporarily)
  • Git Stash List View the stash records
  • Git Stash clear Clears all hidden records
  • git stash popRestore and remove (equivalent to the following two operations)
    1. Git Stash apply restores the hidden parts
    2. Git Stash drop Removes the most recent hidden record

7. Configuration files

Configuration file for location:

  1. Global configuration file: a hidden file in the user home directory. Gitconfig.
  2. The repository configuration file: in the. Git /config file in the repository directory.

Configuring the Mailbox syntax

  • –global user.name
  • –global user.email
* --global user.name jasonhww
* --global user.email [email protected]
Copy the code

Configuring alias syntax

  • – global alias. Alias
git config --global alias.st status
git config --global alias.unstage 'reset HEAD'
Copy the code

Ignore files

Add the. Gitignore file to the repository. github.com/github/giti…

9. Other

Multiple keys can be added to a GitHub account, but only one Key can be used for one GitHub account. In this case, you need to configure multiple SSH keys corresponding to different Github accounts through the configuration file.