Git Theory-Work Flow-Common Commands

Git concept and environment installation

1. Git overview

  • And the father of Linux Git Linus Torvalds (Linus Benedic Torvalds) 1969, Finland

  • Git is currently the most advanced distributed version control system in the world.

  • Git is free and open source

  • Git was originally developed to assist the Linux kernel to replace BitKeeper


2. Git environment setup

Environmental installation:

  • Download: https://git-scm.com/ Click download to choose your own computer version.

  • Installation: Double-click Git-2.28.0-64-bit.exe to install it

  • Git source code: https://github.com/git/git/

  • Git GUI: TortoiseGit, a third-party graphical tool for git (small turtle, can be distinguished by color, the file is modified, submitted, etc.), after installation, you need to restart the computer to have symbols.

Insert picture description here

Note: The directory cannot have Chinese characters, spaces, preferably words and numbers. You can install a TortoiseGit turtle client, which is very smooth.

After installation: the right mouse button has Git and TortoiseGit options and the installation is successful

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-aJCxiN2W-1600085553501)(E:\Typora File\image-20200914193201121.png)]

Version control concept

1. Backup and restore

  • Backup: make a copy of current data

  • Restore (restore): Overwrite the current data with the data of the previous copy (buy on behalf of others)
    Insert picture description here

2. Comparison: compare the difference between two data (compare/diff)

  • Overall comparison: hash value comparison (tool: Hash verification tool)

      The hash value is to call the digest algorithm (md5, sha-1, sha-256, crc. and other digest algorithms) to generate a feature code, and use the feature code to compare whether the two files are the same.

       SHA1 algorithm: fixed length comparison (the hash code value obtained is the same, the file content is the same)

  • Detailed comparison: (line by line comparison)

       Beyond Compare 4: Text comparison tool, compare text content line by line

3. Branch

  To create a "bigger" copy of all current data is to make multiple copies of all current data, and then multiple people can develop at the same time.

  • No interference with the original copy

  • The branch is the same, the current data default branch master (master branch)

  • The significance of branches: improve team efficiency

4. Merger

  By comparing the difference between the two data, the target data and the current data are combined to generate a new data. (Merging is not overwriting. If you add to the original basis, you will merge, and you need to judge the same modification)

  Application: Combine the data of other branches to the main branch (the main branch is not developed, generally used for merging, and the development data is appended to the main branch).

  Conflict: Two (multiple copies) of data, the same position is modified, can not be simply overwritten and replaced, merge according to the actual situation (all will be saved for later modification)


## Centralized and distributed

1. Centralized and Distributed

  • Local version control (personal use, no team collaboration)

  • Centralized version control (team use, data is on the server, can not work offline, the operation will go through the network, continue to write data and read data from the server, the server will have greater pressure) -SVN is the representative of a centralized version control system

  • Distributed version control (team use, data is local to each user, can work offline, Git representatives can read data from the server, and users can also interact with data) [There are server-side warehouses and local warehouses-server, local All data]-Git, the most advanced distributed management system

2. The difference between Git and SVN

  • SVN is the representative of a centralized version control system

  • Git advantages (distributed advantages): Git is a distributed version control system, which has the advantages of high efficiency (team collaboration), offline work, low server pressure, and easy merge.


Git usage process

Insert picture description here

  • workspace: workspace (where you write code)

  • Index: Temporary storage area (submit multiple file seats to the local library at once)

  • Repository: local repository: all version data submitted

  • Remote: remote library, a server used to host code

  (Through the add/commt/push/pull command above, submit/take data from place xx to place xx)

Git workflow

  1. Add and modify files in the working directory;

  2. Put files into the temporary storage area; git addcommand ( git add.add all files to the temporary storage area)

  3. Submit files in the staging area to the local library. ( git commit)

  4. Submit the local library file to the remote library to realize server hosting. ( git push)

All files in the working directory will be submitted to the temporary storage area first, and then submitted to the local library (empty the temporary storage area), because git submission can only submit one file at a time, so they will be placed in the temporary storage area first, and then submitted to the local Library. Then the local library is submitted to the remote library

Git common operation instructions[***]

  1. cdJump to the specified location, the file separator in git is **/**

  2. git init git initialization instruction, after initialization, there will be a .git folder in the specified file (that is, the git system directory)

  3. Classification

  • -Local project level: all current projects are used

  • --Global : current user level use

  • -System : system level (generally not used)

    git config --global git config user.name xxxSet current user name

  1. Configure username and email

    git config --global user.name "用户名"

    git config --global user.email "[email protected]"

  2. Git builds a local warehouse git clone / git init

  • $ git init Create a new Git code library in the current directory

  • $ git init [project-name] Create a new directory (named project-name) and initialize it as a Git code block

  • $ git clone [url] Download a project and its entire code history

  1. git add command

    Write from the work area to the temporary storage area

    $ git add [file1] [file2] Add the specified directory to the temporary storage area, including subdirectories

    $ git add [dir] Add all files in the current directory to the temporary storage area

    $ git add . Click to add all files in the current directory to the temporary storage area

    $ git add -p For multiple changes of the same file, it can be submitted in stages

  2. git view command

  • git status `command

    Display the status of the working directory and temporary storage area, only to the file

    • git logcommand

      Display project history information

    • git log --statcommand

      View summary statistics

    • git show sha1 or head tag

      See the changes to a specific commit

    • git diffcommand

      Display the status of the working directory and temporary storage area, down to the content

    • git diff HEADcommand

      Display the working directory and the last state, down to the content

  1. git commit command: Submit files in the staging area to the local library
  • $ git commit -m [message] Submit the specified files in the temporary storage area to the local library
  1. Branch merge [***This is the point]
  • $ git branch [branch-name] Create a new branch, but still stay in the current branch
  • $ git switch [branch-name] Switch branch
  • $ git switch master Merge other branches into the current master branch

Guess you like

Origin blog.csdn.net/qq_40542534/article/details/108586993