Git easy to use

Time:2021-9-9

Git installation package download:
Link: https://pan.baidu.com/s/18B8W… Extraction code: ykvf

1、 Git basic model
Git easy to use

  • Workspace: workspace is the directory file you see
  • Index / stage: the temporary storage area is used to temporarily store your changes. In fact, it is just a file to save the information to be submitted to the file list
  • Repository: a local warehouse is a safe place to store data, which contains the data you submit to all versions. Where head refers to the latest version put into the warehouse
  • Remote: a remote warehouse, a server that hosts code

2、 File 4 states

  • Unmodify: unmodified, that is, the contents of the file snapshot in the version library are exactly the same as those in the folder. If it is modified, it becomesModified. if usedgit rmIf you move out of the version library, it becomesUntrackedfile
  • Untracked: untracked status. It is generally a newly created file and is not under version control   Can passgit add  The status changes toStaged.
  • Modified: modified status,   adoptgit addCan enter temporary storagestagedStatus, usinggit checkout  Discard the modified and return tounmodifystate
  • Staged: staging status   implementgit commitThen synchronize to the local warehouse. At this time, the files in the library and the local files become consistent, and the file isUnmodifystate

3、 Git warehouse copy

1. Create a git code base in the current directory

> git init

2. Clone remote warehouse

>Git clone [- B branch] [-- depth 1] remote warehouse address

-B branch: Specifies the branch to be cloned
–Depth 1: depth is used to specify the clone depth. A value of 1 means that only the last commit is cloned

3. Relevant settings

>Git config -- list # view git related configurations

># set the submitted user name and mailbox information -- Global: global configuration
>Git config [-- global] user.name 'GitHub user name'
>Git config [-- global] user.email 'mailbox'

>I # set and save the account password. This is only the first submission. You need to enter the account password
> git config --local credential.helper store

4、 Git common operations

1. Upload local files to remote warehouse

>Git add file # from workspace to staging area
>Git commit - M 'description of this submission' # from the staging area to the local warehouse
>Git push # push to remote warehouse

2. Pull from remote warehouse to local workspace

>Git fetch # obtains the latest version remotely and merges directly
>Git merge # merges the remote branch and the local branch, and the workspace is updated

perhaps

>Git pull # obtains the latest version remotely and merges it directly with the local branch, which is equivalent to git fetch & & git merge

3. Other common commands

># view status
> git status

># view commit log
> git log [-p]

># view changes
> git diff 

>#git undo changes
>Git checkout -- file # staging area file overwrite workspace
>Git checkout master -- file # local warehouse file covers the temporary storage area and work area, which is only applicable to git add files
>Git checkout origin / Master -- file # remote branch file covers the temporary storage area and work area. It is applicable to git commit files, but the local warehouse has been modified. You can execute git push to submit to the remote warehouse. At this time, the local directory is different from the remote warehouse file and cannot be updated through git pull. You can execute git checkout master -- file

>## revision submission
>Git commit -- amend - M 'comment' # can only modify the comments just submitted

>## version fallback (use with caution)
>Git reset -- hard head ^ # fallback to the previous version, equivalent to head ~ 1
>Git reset \ - hard version number # fallback to the corresponding version

Record common operations for reference only!