Git is a distributed version control system designed to handle tasks in an agile and efficient manner.

A, install,

  • The Windows version
  • Linux version
  • OSX version

2. Git version control file location structure

  • Workspace: Your working directory that actually holds files. Local files are created and modified locally.
  • Staging: With git add, a snapshot of the workspace files is created in staging, which acts as a bridge between the workspace and the local repository. The contents of the workspace can also be restored from here.
  • Local repository: Create a local repository after git init in the working directory. Run the git commit command to save the snapshot file version in the staging area to this location. If the file is not saved to the staging area, you cannot use the commit command to save the snapshot file to the local repository. Include the HEAD section, where the HEAD points to the last result you submitted.
  • Remote repository: The git push command commits the local repository files to the remote repository.

Iii. Workflow

Generally speaking, the direction order is workspace, staging area, local warehouse, remote warehouse.Copy the code

In particular, you can use ‘git checkout — file name’ to overwrite the file contents of the workspace to the file contents of the staging area. Use ‘git rm –cached file name’ to untrack the file.

Local warehouse

  1. Pointer to the HEAD

Enter ‘Git log’ on the terminal to view the history of the submission to the local repository. Git log –pretty=oneline For example, the following information is displayed:

A0c399145bb7b413a54593ca0f11c3e1eda2ef83 I changed 65 b88a34150e77b3ba6122238fd1e6b4609f0e85 I just createdCopy the code

According to the above results, it was submitted twice. The preceding string represents the COMMIT ID. Git init creates a master branch with the current version as ‘HEAD’, the previous version as ‘HEAD^’, and the previous version as ‘HEAD^^’. The pre-web version is denoted by HEAD~ number. In particular, HEAD~0 indicates the current version and HEAD~1 indicates the previous version. You can run the ‘git rev-parse HEAD’ command to obtain the latest version number. You can also run the ‘git rev-parse –short HEAD’ command to obtain the seven-digit short version number.

  • Overwrite the contents of the staging area file with the current version of the repository file:Git reset HEAD File name
  • Overwrite the staging area file to the previous version of the warehouse file:git reset --hard HEAD^Or check the previous version number and then reuse itGit reset -- Hard version numberThe instructions.

2. Branch management

  • The branch switch

Use ‘git branch’ to view the current branch. * master is displayed, where the symbol ‘*’ indicates the current branch. Create a new branch using ‘Git branch name’. For example, after git branch branch_1, switch the branch to Git checkout branch_1. Git branch = ‘git branch’

$ git branch
* beta_v1
 master
Copy the code
  • Branch merge

Changing the contents of a file on a different branch does not affect the situation on the other branch, unless you use ‘Git merge branch name’ to overwrite the contents of a file on the current branch.

Reference links: Example tutorial, Git guide