Centralized (SVN)

Because the SVN saves the difference each time, it requires relatively small disk space, but the rollback speed is slow. Advantages: The code is stored on a single server, which is convenient for project management. Disadvantages: The server breaks down: the code written by employees cannot be guaranteed, and the server explods: the historical records of the whole project will be lostCopy the code

Distributed (git)

Git saves a full snapshot of the project each time and requires a relatively large amount of hard drive space (the Git team does extreme compression of the code and ends up with not much more real space than SVN, but Git rolls back very quickly) Advantages: Complete distribution Disadvantages: steep learning curve compared to SVNCopy the code

Git configuration

  • Git initial configuration

Usually on a new system, you need to configure your Git working environment first. The configuration only needs to be done once, and the current configuration will be used in future upgrades. Of course, you can always use the same command to modify existing configurations if needed. Git provides a command called Git config to configure or read the corresponding environment variables, and it is these environment variables that determine the specific Git operation mode and behavior. These variables can be stored

In three different places:

  • The /etc/gitconfig file: the configuration that is universally applicable to all users in the system. If you use the –system option when using git config, you will read and write this file.
  • ~/. Gitconfig file: The configuration file in the user directory is only applicable to the user. If you use the –global option in git config, you will read and write this file.
  • Git /config file: the configuration file in the current project’s git directory (i.e., the.git/config file in the working directory) the configuration here is only valid for the current project.
  • Each level of configuration overrides the same configuration at the upper level

  • Configuration content: User information:
  • The first thing to configure is your personal username and email address. These two Settings are important because they are referenced every time Git commits to indicate who committed the update, so they are permanently included in the history along with the update:
  • git config --global user.name "damu" — generates a global configuration for user.name
  • git config --global user.email "[email protected] "— Generates a global configuration for user.email
  • To check the existing configuration, use the git config –list command
  • Git config –global –unset user.email

Initialize the new warehouse

To start git management of an existing project, simply go to the directory where the project is located and run the following command: git init Function: After initialization, a directory named. Git will appear in the current directory, and all the data and resources required by git will be stored in this directory. So far, we’ve only initialized all the files and directories in the existing framework, but we haven’t started tracking and managing any of the files in the project. . Git directory

  • Hooks — The hooks directory contains hook scripts for the client or server
  • Info — Contains a global exclusion file
  • Logs — Stores log information
  • Objects — A directory that stores all data content
  • Refs — directory stores a pointer (branch) to the commit object that points to the data
  • Config — The file contains project-specific configuration options
  • Description – Displays a description of the repository
  • HEAD — File indicating the branch currently checked out
  • Index — Information about the staging area of the file

Basic environmental concepts


  • The workspace
    • Sandbox environment – Modify files
  • The staging area
    • Save the modified file temporarily
  • repository
    • Storage version

Underlying command object

  • Git hash-object -w fileUrl: generates a key(hash value), val(compressed file content), and stores the key-value pair in. Git /objects
  • Git update-index –add — cacheInfo 100644 hash test.txt: Git /index git write-tree: save the.git/objects generation tree to.git/objects
  • Commit object echo ‘first commit’ | git commit – tree treehash: submit object to generate a. Git/objects
  • Query the preceding objects. Git cat-file -p hash: obtains the content of the corresponding object. Git cat-file -t hash: obtains the type of the corresponding object

View the staging area

  • git ls-files -s

Git Low-level concepts (Low-level commands) Basic Linux commands

  • Clear: clear the screen
  • Echo ‘test content’ : output information to the console echo ‘test content’ > test.txt
  • Ll: Spread the subfiles & subdirectories in the current directory on the console
  • Find directory name: Tile files in the corresponding directory & the descendant directory on the console find directory name -type f: tile files in the corresponding directory on the console
  • Rm File name: deletes a file
  • Mv Source file Rename file: Rename
  • Url of cat file: view the contents of the corresponding file url of vim file (in English mode)
  • Press I in insert mode to edit the file
  • Press ESC & Press: to execute the command
  • q! Force exit (without Saving)
  • Wq Save and exit
  • Set nu Sets the line number

Git objects – one-time versions of files

The heart of Git is a simple key-value pair database. You can insert any type of content into the database, and it will return a key that can be retrieved again at any time

  • Writes to the database and returns the corresponding key

Command: echo ‘test content’ | git hash – object – w – the stdin -w option instructs hash – object commands stored data object; If this option is not specified, the command returns only the corresponding key — the stdin (Standard Input) option indicates that the command reads from standard input; If you do not specify this option, you must specify the path of the file to be stored at the end of the command. Git hash-object -w File path: Save file Git hash-object file path: Returns the key values of corresponding file d670460b4b4aece5915caf5c68d12f560a9fe3e4 return: the command output a checksum length is 40 characters. This is a SHA-1 hash

  • Find the one that stores data

Git/objects-type f — find the stored data in the command path

  • Pull data based on key valuesgit cat-file -p/-t d670460b4b4aece5915caf5c68d12f560a9fe3e4

The -p option indicates that the command automatically determines the type of the content and shows us the format friendly content returned: the contents of the corresponding file. -t returns its type, which is typically Bolb

  • Write to a single file
    • git hash-object -w test.txt— Write the test.txt file to the stored data
    • find ./.git/objects/ -type f— View all data written
    • git cat-file -p ddbb2d26d3ff8b7afd7eca2b75a60c7f19be97ccView the compressed hash value of the source text

Build the tree object – a one-time version of the project

Tree Object, which solves the file name problem and allows us to organize multiple files together. Git stores content in a way similar to UNIX file systems. All content is stored in the form of tree objects and data objects (Git objects), where tree objects correspond to directory entries in UNIX, and data objects (Git objects) correspond roughly to file contents. A tree object contains one or more records (each record contains a SHA-1 pointer to a Git object or subtree object, along with the corresponding schema, type, and file name information). A tree object can also contain another tree object. We can use update-index; The write – tree; Command such as read-tree to build tree pairs and shove them into the staging area.

Let’s say we do a bunch of operations and we get a tree object operation

  • Use the update-index command to create a staging area for the first version of the test.txt file –. Run the write-tree command to generate tree objects.

Command: git update – index – add – 100644 83 baae61804e65cc73a7201a7252750c76066a30 cacheinfo test. TXT git write – tree

  • File mode is
    • 100644, indicating that this is a normal file
    • 100755, an executable file;
    • 120,000, which represents a symbolic link.
  • – the add options:

Because the file did not need -add in the staging area the first time

  • – cacheinfo options:

Because the file to be added is in the Git database, not in the current directory where all the required – cacheInfo

  • Add new.txt to the second version of new.txt and test.txt files

Into the temporary storage area. Run the write-tree command to generate tree objects. Command: echo ‘new file’ > new.txt git update-index –cacheinfo 100644 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a test.txt git update-index –add new.txt

git write-tree
3. Add the first tree object to the second tree object to make it a new tree object
git read-tree –prefix=bak d8329fc1cc938780ffdd9f94e0d364e0ea74f579
git write-tree
The read-tree command reads a tree object into the staging area

  • Git cat-file -p master^{tree}
    • The master^{tree} syntax indicates the tree object to which the most recent commit on the master branch points.
  • Parse tree object

Git creates and records a corresponding tree object according to the state represented by the staging area (i.e., the index area) at a certain moment, and repeats this to record a series of tree objects in turn. In fact, the tree object is an abstraction of the operation in the staging area. This tree object is the snapshot. When any changes to our workspace are synchronized to the staging area. The write-tree command is invoked to write a tree object to the staging area contents. It automatically creates a new tree object based on the current staging state. That is, each synchronization produces a tree object. And the command returns a hash to the tree object. In Git, every file (data) corresponds to a hash (type blob) and every tree object corresponds to a hash (type tree)

Submit the object

We can create a commit object by calling the commit-tree command, specifying the sha-1 value of the tree object and the parent commit object of the commit (if any, there is no parent when we first snapshot the staging area).

  • Create the submission object echo ‘first commit’ | git commit – tree d8329f

Returns: fdf4fc3344e67ab068f836878b6c4951e3b15f3d (hash value)

  • Viewing the Submitted object

Git cat – file – p fdf4fc3 returns: tree d8329fc1cc938780ffdd9f94e0d364e0ea74f579

  • Format of the submitted object

The format of the commit object is simple: it specifies a top-level tree object that represents a snapshot of the current project. Then the author/submitter information (based on your user.name and user.email profiles, plus a timestamp); Next, we’ll create two more commit objects, each of which references the previous commit (as its parent) : Echo ‘second commit’ | git commit tree eb – 0155 – p fdf4fc3 (submit in addition to the first object is the chain no bosses, Other versions will be take it on a version of the 0155 exabytes (second version) – p fdf4fc3 (first edition) echo ‘third commit’ | git commit – 3 c4e9c – p cac0cab tree

  • Pay attention to

Git commit-tree not only generates commit objects but also commits the corresponding snapshots (tree objects) to the local library

Process simplification operation (high level command -CRUD)

Create a working directory Modify a working directory

  • Git init initializes the repository

  • Git status — Check the status of the file
  • Git diff (no parameters) –(which updates are currently not staged)
  • With arguments :git diff — cached or Git diff — staged (- recommended)(has the update been staged ready yet not committed?)
  • Git log –oneline / –pretty=oneline — check the committed version history

  • git add ./

    • Git hashing -object -w file name (how many times this command must be executed to modify files in the working directory)
    • git update -index –add …
  • Git rm file name Delete the corresponding file in the file directory and add the changes to the staging area

  • Git mv Source file name New file name Rename the files in the file working directory and add the changes to the temporary area

  • Git commit vim

  • Git commit -a — skip the staging area

  • Git commit -m “” — comment content

  • Git commit -a -m “” comment content to skip the staging area

  • Gir write-tree — Write tree

  • Git commit-tree — Commit tree

Branch operation

  • Git Branch – Displays a list of branches

  • Git Branch name — Create a branch

  • Git branch-v — you can see the last commit for each branch

  • Git branch -d / -d name ‘– delete branch -d forcibly delete

  • Git checkout lys(branch name) — switch branches

  • Git log –oneline — classpiles –graph –all

  • Git merge Branch name — Branch merge

  • Git branch — merged to check branches merged into the current branch list. Branches that don’t have asterisks (*) before their names can usually be removed using git branch -d.

  • Git config –global alias. name The name of the command — alias a command for ease of use

    • git config --global alias.lol "log --oneline --decorate --graph --all" (Alias the command lol) Run git LOL

The Tag label

  • git tag — List tags
  • git tag tagnameGive the current branch, version a tag name
  • git tag tagname commitHashGive the specified version (Hash) a tag name
  • git show tagname— View the specified label information
  • git tag -d tagnameDelete the specified label v1.0
  • git checkout tagname— Check out toggle the specified TAB version (if the specified TAB version does not branch, it will cause header separation)Git checkout - b "v1.0")

Summary use of the command

The installation

git --version
Copy the code

Initial Configuration

git config --global user.name "damu"
git config --global user.email [email protected]    
git config --list
Copy the code

Initializing the warehouse

git init
Copy the code

C (new)

Git status git add./ git commit -m "MSG"Copy the code

U (modified)

Git status git add./ git commit -m "MSG"Copy the code

D(delete & Rename)

Git status git status git commit -m "MSG" git commit -m "MSG" git commit -m "MSG"Copy the code

R (query)

Git status: Check the status of files in the working directory (tracked (committed, staged, modified), not tracked) git diff: Check the unstaged changes git diff --cache: Check the uncommitted staged git log --oneline: View the submission recordCopy the code


The essence of a branch is a commit object!! HEAD: It's a pointer and by default it points to the master branch and when you switch branches you just want the HEAD to point to a different branch and every time there's a new commit the HEAD will move forward with the branch that it's currently pointing to. Git log --oneline -- class --graph --all: Git branch -v: check the latest commit of the branch. Git branch name: Create a new branch on the current commit. Git branch -d name: deletes empty branches. Git branch -d name: deletes branches that have been mergedCopy the code

Branch operation

Git Branch

A branch is essentially a commit object, and all branches have a chance to be referred to by the HEAD (the HEAD only points to one branch at a time). When we have a new commit, the HEAD carries the current branch forwardCopy the code

Git Branch command

Branch branch: git checkout -b branchname Git branch -d branchname Git merge Branchname Fast forward merge --> no conflict typical merge --> Chance of conflict resolution conflict --> open the conflict file for modification add COMMITCopy the code

If git branch is merged into the next branch, delete it from the git branch merged list. If git branch is merged into the next branch, delete it from the next branch list. Git Branch –no-merged once it appears in this list you should check to see if you need to merge

Git branch note & store

Make sure the current branch is clean when switching!! Allow to switch branches: All content on a branch is in the committed state (avoid). Content on a branch is initialised and created. Content on a branch is initialised and created in the untracked state (avoid). All the work on a branch is in the modified or temporary state after the second one. If there is a need to switch branches halfway through the branch work, we should stash the existing work into git Stash: Git Stash Apply: Restore the work at the top of the stack without letting anything out of the stack. Git Stash pop: Git Stash apply + Git stash Drop Git Stash listCopy the code

Regret medicine

Git reset HEAD filename git restore --staged bidus.txt git commit --amendCopy the code

Reset the trilogy

Git reset [--mixed] commithash --> reset HEAD with commithash Git reset --hard commithash --> Reset the work directory with commithashCopy the code

Path to the reset

All paths reset should omit the first step!! The first step is to reset the contents of the HEAD. We know that the essence of the HEAD is to point to a branch. The essence of the branch is a commit object. HEAD can represent the status of a series of files!!!! Git reset [--mixed] commithash filename Resets the temporary area with the contents of the commithash filenameCopy the code

Checkout in-depth understanding

Git checkout brancname (" checkout ") and Git reset (" checkout ") have the same characteristics as git reset (" checkout ") Git checkout commithash filename resets the working directory of git checkout -- filename Resets the working directoryCopy the code


NPX eslint --init check js file NPX eslint --init check js file NPX eslint --init check js file NPX eslint --init check js file NPX eslint --initCopy the code

Eslint combined with git

Husky: husky, set hook procedure used for Git repository In the warehouse after the initialization To install the huskies in package. Json file write configuration "husky" : {" hooks ": {" pre - commit" : "NPM run lint" "NPM run lint" "NPM run lint" "NPM run lint" "NPM run lint"Copy the code

Common commands for remotely operating repositories

  • git remote add < shortname > < url>Add a new remote Git repository and specify a shorthand that you can easily refer to
  • Git remote - vDisplays the Git alias used by the remote repository and its corresponding URL
  • git branch -vv— View all branch trace Settings
  • git remote show [remote-name]— See more information about a particular remote repository
  • git remote rename pb paul– rename
  • git remote rm [remote-name]If you want to remove a remote repository for some reason – you have removed it from the server or no longer want to use a particular image, or a particular contributor is no longer contributing
  • git config --global --unset user.name [name] Delete global user.name from user.name[name]Can not write
  • git config --global --unset user.email [name] — Delete user.email from global Settings[name]Can not write

  • Git push [remote-name] [branch-name] — Push the master branch of a local project to the Origin server

  • Git Clone URL – clone a remote repository to a local directory (no Git init required)

  • Git fetch [remote-name] — This command accesses the remote repository and pulls all data from it that you don’t already have. When complete, you will have a reference to all branches in that remote repository, which you can always merge or view —— It is important to note that the Git fetch command will pull data to your local repository – it does not automatically merge or modify your current work. You must manually incorporate it into your work when it is ready.

    • git megre branch-nameMerge branches
  • Git push Origin serverFix — Push a branch named serverFix to a remote repository

    • git push origin serverfix:awesomebranch— You can also change the name when you push it
  • Git pull – fetching data that does not have a remote repository locally

  • Git push — push local data to a remote repository

    • git push remote-name branch-name— You can also specify which branch to push and which branch to push to the remote repository
  • Git branch -u remotename/branchname — Trace the branch of the remote repository at the current branch

  • Git checkout -b serverfix origin/serverfix — keep track of remote branches (other collaborators) while creating branches

    • git checkout --track origin/serverfixThis is such a common action that Git provides a –track shortcut — serverFix alias as well as tracing branch names

  • git push origin --delete serverfix— // Delete the remote branch
  • git remote prune origin --dry-run— // List branches that are still being traced remotely but have been removed
  • git remote prune origin — // Clear the remote trace listed above

The pull request process

If you want to participate in a project but do not have push permissions, you can “Fork” the project. Derived means that GitHub will create a copy of your project in your space that you can push. This way, project managers no longer need to be busy adding users to the contributors list and giving them push privileges. People can derive the project, push changes to the derived copy of the project, and get their changes into the source repository by creating Pull requests. Basic process:

  1. Create a new branch from the master branch (your own fork project)
  2. Commit some changes to improve the project (your own fork project)
  3. Push the branch to GitHub (your own fork project)
  4. Create a merge request
  5. Discuss, continue to modify according to the actual situation
  6. The project owner merges or closes your merge request

Note: Every time you launch a new Pull Request, Pull the code from the latest source repository, not the repository you fork.

  • Git remote add
  • Git fetch Remote repository name
  • Remote trace branch for git merge

Three must understand the concept

Local branch Remote tracing branch (remote/ branch name) Remote branchCopy the code

The basic flow of remote collaboration

Step 1: The project manager creates an empty remote repository Step 2: the project manager creates a local repository to be pushed Step 3: Alias the remote repository Step 4: Initialize the code in the local repository Step 5: push Step 6: Invite members Step 7: Member clone remote repository Step 8: Member makes changes Step 9: Member pushes his or her changes Step 10: Project manager pulls member's changesCopy the code

Do the tracking

Git branch -u -u -u -u -u -u -u -u -u -u -uCopy the code


git push
Copy the code


git pull
Copy the code

pull request

Involve third party personnel in the projectCopy the code

The five most frequently used commands

git status
git add
git commit
git push
git pull
Copy the code

Remote branch

Remote tracking branch

The local branch

Normal data push and pull steps 1. Ensure that the local branch has tracked the remote trace branch 2. Pull data: git pull 3. Upload data: git push a local branch how to track a remote tracking branch 1. When cloning, a master branch will be generated automatically (the remote branch has been traced). Git checkout -b local branch name remote branch name git checkout --track Remote branch name 3. Change an existing local branch to a trace branch git branch -u remote trace branch nameCopy the code

Team collaboration

1. The project manager must initialize an empty warehouse when initializing the remote warehouse; 2. Project manager create local git remote alias repository (HTTPS) git init; Git add git commit 3. Project manager pushes local repository to remote repository to clean Windows credentials git push alias branch (enter user name and password; 4. Project invites members & members accept the invitation to operate on Github 5. Git master = master /master = master /master = master /master = master /master Git add git commit Git push alias branch (enter username and password; The project manager updates the Git FETCH alias (synchronizes the changes to the remote trace branch)Copy the code


Is there any conflict with git local operations? Will there be conflicts when git collaborates remotely in a typical merge? Push pull modify and submit againCopy the code

Ignore some files

  • .gitignoreFile write conditions such as: folder or regular expression


SSH: C:\Users\ administrator. SSH SSH -t [email protected]: test whether the public and private keys are paired