God tools Git development

About the author

  • The authors introduce

🍓 blog home page: author’s home page 🍓 Introduction: JAVA quality creator 🥇, a junior student 🎓, participated in various provincial and national competitions during school, and won a series of honors


1, the version control tool should have functions

  1. Synergy to modify
    • Multiple people simultaneously modify the same file on the server side.
  2. The data backup
    • Save not only the current state of entries and files, but also the historical state of each submission.
  3. Version management
    • When saving file information of each version, do not save duplicate data to save storage space and improve operating efficiency. In this aspect, SVN adopts incremental management, while Git adopts file system snapshot. |
  4. Access control
    • Control the permissions of the team members involved in the development.
    • Review code contributed by outside developers – Git only.
  5. The historical record
    • View the modified person, modified time, modified content, and log information.
    • Restores a local file to a historical state.
  6. Branch management
    • Allow the development team to work on multiple production lines simultaneously to further improve efficiency.

2. Introduction to version control

2.1 Version Control

The engineering design field uses version control to manage the design process of engineering blueprints. Versioning ideas can also be used to manage iteration of code during IT development.

2.2 Version Control Tool

Idea: version control Implementation: version control tools

Centralized version control tools: CVS, SVN, and……

Distributed version control tools :Git, Mercurial, Bazaar, dar.c……

3. A brief history of Git

3.1 history

3.2 Git official website and Logo

It-scm.com It-scm.com

3.3 the Git advantage

  1. Most operations are done locally and do not require an Internet connection
  2. Integrity assurance
  3. Whenever possible, add data rather than delete or modify it
  4. Branching is very fast and smooth
  5. Fully compatible with Linux commands

3.4 the Git structure

3.5 Git and code Hosting Center

  • Local area network (LAN)
    • GitLab server
  • In the extranet case
    • Github
    • Cloud Gitee (yards)

3.6 the Git installed

3.7 Local and Remote Libraries

  • Intra-team collaboration

  • Collaboration across teams

4. Git command line operation

4.1 Initialization of the local Library

  • Git add command

    • Effect:
  • Command: git init

    • Effect:

Note: the.git directory contains local library subdirectories and files. Do not delete or modify them at will

  • Ll Loads resources in the current directory
  • Ls -la Load Hidden resources in the current directory
  • The ls -l | less | split screen view
  • PWD Displays the working directory
  • CD ~ Go to the home directory
  • If the following information is displayed: One page is full. Press the space to go to the next page
  • Reset clears the screen with the Enter key

Vim editor

  • : wq Save the changes and exit
  • Esc exits editing mode
  • Set nu Displays the line number
  • Git /config Check the information

4.2 Setting a Signature

  • In the form of

    User name: Tom Email address: [email protected]

  • What it does: Distinguish the identities of different developers

  • Setting a signature has nothing to do with logging in to a remote repository (code hosting center).

  • Command:

    • Project level/repository level: valid only within the scope of the current local library

      • git config user.name zhangmazi_pro

      • git config user.email [email protected]

      • Git /config file

    • System User level: specifies the user level for logging in to the current OPERATING system

      • git config –global user.name zhangmazi_glb

      • git config –global user.email [email protected]

      • git config --global user.name zhangmazi_glb
        git config --global user.email [email protected]
        Copy the code
    • Level Priority

      • Proximity rule: Project level takes precedence over system user level, and both sometimes use project-level signatures
      • If only the system-level signature is available, use the system-user signature
      • Neither is not allowed

4.3 Basic Operations

4.3.1 Checking git Status – Git status

View the status of working area and temporary storage area

4.3.2 Git add [file name]

Add workspace new/modification to the staging area

4.3.3 Commit – git commit -m “commit message” [file name]

Commit the contents of the staging area to the local library

Git rm –cached good. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT — git rm –cached goo. TXT To continue to commit to a remote repository, use git commit good.txt. But a Vim editor will appear that allows you to describe the submitted content.

Press the A or E key to enter editing mode

After editing, press Esc and enter :wq to exit the vim editor

Git status automatically detects that our file has been modified

#Using specific submissions no longer enters the Vim editor but is described at the time of submission
$ git commit -m "My second commit,modify good.txt" good.txt
Copy the code

4.3.4 Querying Historical Records – Git log

Git log #Copy the code

** Multi-screen display control mode: space to scroll down, B to scroll up, Q to exit. ** If “:” is displayed, it indicates that the content is not finished in one page. Press the space to enter the next page until it appears (END)

Git log --pretty=onelineCopy the code

Git log --oneline # hash shortenedCopy the code

Git reflog # on the Oneline version shows how many steps it takes to move to another version#HEAD@{how many steps to move to current version}
Copy the code

— git reset –hard

  • nature

  • Operation based on index value
Git reset --hard git reset --hard 4dc987cCopy the code

  • Use ^ symbol: only backward

Git reset --hard HEAD^ ##Note: one ^ means one step back, n means n steps back
Copy the code
  • Use the ~ symbol: only back
Git reset --hard HEAD~N #Copy the code

4.3.6 Comparison of the Three Parameters of commands

  • – soft parameter

    • Move the HEAD pointer only in the local library

  • – mixed parameter

    • Move the HEAD pointer in the local library
    • Reset the staging area

  • – hard parameters

    • Move the HEAD pointer in the local library
    • Reset the staging area
    • Resetting the workspace

4.3.7 Deleting a File and Retrieving it -rm [File name]

Prerequisite: Before deletion, the existing state of the file is committed to the local library.

Git reset –hard

  • Delete operation and commit to local library: pointer position points to history
  • Delete operation not committed to local library: HEAD is used for pointer position

  • Retrievable after permanently deleting files

rm aaa.txtgit statusgit commit -m "new aaa.txt" aaa.txtrm aaa.txtgit add aaa.txtgit commit -m "delete aaa.txt" aaa.txtgit refloggit reset --hard 26b6196
Copy the code
  • Retrieve deleted files added to staging area

4.3.8 Comparing files — git diff

Git diff # compare files in your workspace with local library history # compare multiple files without filenameCopy the code

4.4 Branch Management

4.4.1 What is a branch?

In version control, multiple lines are used to recommend multiple tasks simultaneously.

4.4.2 Benefits of branching?

4.4.3 Branch Operations

  • Git branch

  • Check out the branch — git branch -v

  • Git checkout

  • Git merge

    • Step 1: Switch to the branch that receives changes (cup merge, add new content)

      Git checkout

    • Step 2: Run the merge command

      Git merge [branch name with new content]

  • Resolve the conflict

Using vim apple.txt to set the content of both questions to the same content will conflict, then need to manually merge branches.

This happens because the contents of both files are in conflict.

  • Expression of conflict

  • Conflict resolution
    • Step 1: Edit the file and delete the special symbols
    • Step 2: Modify the file to a satisfactory degree, save and exit
    • Git add [filename]
    • Git commit -m
      • Note: Commit must not have a specific file name

5, Git basic principles

5.1 the hash

Hash is a series of encryption algorithms, each different hash algorithm although the encryption intensity is different, but there are several common points: (1) no matter how much data input data, the input of the same hash algorithm, the length of the encryption result is fixed. ② Hash algorithm is determined, the input data is determined, the output data can be guaranteed unchanged ③ Hash algorithm is determined, the input data is changed, the output data. Git hashing is irreversible. The underlying Git hashing algorithm is sha-1. Hashing algorithms can be used to validate files. The principle is shown in the figure below:

5.2 Version Saving Mechanism

5.2.1 File management mechanism of the centralized version control tool

Store information as a file change list. Such systems treat the information they hold as a set of basic files and differences that accumulate over time for each file.

5.2.2 Git file management mechanism

Git views data as a set of snapshots of a small file system. Every time Git commits an update, it takes a snapshot of all the current files and stores the index of that snapshot. To be efficient, Git doesn’t re-store the file if it hasn’t been modified, but only keeps a link to the previously stored file. So the way Git works is called snapshot flow.

5.2.3 Details of Git file management mechanism

  • Git’s “commit object”

  • A chain of submitted objects and their parent objects

5.3 Git Branch Management Mechanism

5.3.1 Branch Creation

5.3.2 Switching branches

6, Gitee

6.1 Account Information

Official website: gitee.com/

6.1.1 Modifying the Profile picture

6.2 Creating a Local Repository

You don’t need to fill in the rest

Once created, copy the site’s address

Then go to Git Bash

Git remote - v # check alias git remote add origin https://gitee.com/z6135/test.git # will address assigned to originCopy the code

6.3 Push – Git push

git push origin master
Copy the code

That’s a success!

6.4 Git Clone – Git clone

Effect:

  1. Download the complete remote library to the local
  2. Example Create the origin remote address alias
  3. Initialize the local library

6.5 Invite others to join the team

Push up does not need to log in because of the credentials in the computer

6.6 pull

  • pull=fetch+merge

  • Git fetch [remote branch name]

    git fetch origin mastercat test.txt
    Copy the code

  • Git merge

    git merge origin/master	cat test.txt
    Copy the code

    Outside the chain picture archiving failure, the source station might be hotlinking prevention mechanism, proposed to directly upload picture preserved (img – guShYixa – 1632892472422) (.. / AppData/Roaming/Typora/Typora – user – images/image – 202109 27215821918.png)]

6.7 Conflict Resolution

  • The main points of
    • If the changes are not based on the latest version of the Gitee remote library, they cannot be pushed and must be pulled first.
    • If a conflict occurs after being pulled down, perform “Branch Conflict Resolution” to resolve the conflict.
  • analogy
    • Creditor: Lao Liu
    • Debtor: Xiao Zhang

6.8 Cross-team Collaboration

Local modification, then push to remote, then Pull request

After the language

The original intention of the director to write blog is very simple, I hope everyone in the process of learning less detours, learn more things, to their own help to leave your praise 👍 or pay attention to ➕ are the biggest support for me, your attention and praise to the director every day more power.

If you don’t understand one part of the article, you can reply to me in the comment section. Let’s discuss, learn and progress together!

Wechat (Z613500) or QQ (1016942589) for detailed communication.