Four, Git local library operation

1 Local library initialization

  • Command: git init
  • effect:
    Insert picture description here
  • Note: The subdirectories and files related to the local library are stored in the .git directory. Do not delete or modify them.

1.1 Set signature

  • form
  • Role: distinguish the identities of different developers
  • Discrimination: The signature set here has nothing to do with the account and password for logging in to the remote library (code hosting center)
  • command:
    • Project level/warehouse level: only valid within the scope of the current local library

      • git config user.name tom_pro
      • git config user.email [email protected]
      • Information storage location: ./.git/config file
        Insert picture description here
    • System user level: the range of users who log in to the current operating system

      • git config --global user.name tom_glb
      • confug sit --global user.email [email protected]
      • The location where the information is saved: ~/.gitconfig fileInsert picture description here
    • Level priority:

      • Proximity principle, project level takes precedence over system user level, both of which sometimes adopt project level signature
      • If there is only a system user-level signature, the system user-level signature shall prevail.
      • Neither is allowed.

2 Basic operation

2.1 Status check

git status
View the status of the workspace and temporary storage area
Insert picture description here

2.2 Add

git add [file name]
adds the "new/modified" of the workspace to the staging area

  • Before adding:
    Insert picture description here
  • After adding
    Insert picture description here
    Insert picture description here

2.3 Delete

git rm --cached [file name]
delete the contents of the temporary storage area
Insert picture description here

2.4 Submit

git commit [file name]
Submit the contents of the temporary storage area to the local library
Insert picture description here
Insert picture description here
Insert picture description here
After modifying the file, execute git status and
Insert picture description here
execute the git add command to add the file to the temporary storage area.
Insert picture description here
Use the git commit -m "commit message" [file name] command , No need to enter the vim editor to edit this submission information
Insert picture description here

2.5 View history

git log
Insert picture description here

  • Multi-screen display control mode:
    • Space page down
    • b Page up
    • q Exit

git log --pretty=oneline
Insert picture description here
git log --oneline
Insert picture description here
git reflog
Insert picture description here
HEAD@{How many steps does it take to move to the current version}

2.6 Forward and Backward

Nature
Insert picture description here

  • Operation based on index value [recommended]

    • git reset --hard [local index value]
    • git reset --hard a6ace91
      Insert picture description here
  • Use the ^ symbol: only go back

    • git reset --hard HEAD^
    • Note: A ^ means going back one step, n means going back n steps
      Insert picture description here
  • Use ~ symbol: only go back

    • git reset --hard HEAD~n
    • Note: means back n steps
      Insert picture description here

2.6.1 Comparison of the three parameters of the reset command

  • --Soft parameter

    • Only move the HEAD pointer in the local library. The
      Insert picture description here
      Insert picture description here
      local library moves backward, and the contents of the temporary storage area and work area are changed.
  • --Mixed parameter

    • Move the HEAD pointer in the local library
    • Reset the temporary
      Insert picture description here
      Insert picture description here
      storage area. Both the local library and the temporary storage area are backward. It appears that the workspace is updated but not added to the temporary storage area.
  • --Hard parameter

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

2.7 Delete files and retrieve them

  • Prerequisite: Before deleting, the state of the file when it exists is submitted to the local library.
  • Operation: git reset --hard [pointer position]
  • The delete operation has been submitted to the local library: the pointer position points to the historical record
  • The delete operation has not been submitted to the local library: the pointer position uses HEAD

2.8 Compare file differences

  • git diff [file name]

    • Compare the files in the work area with the staging area
      Insert picture description here
  • git diff [historical version in local library] [file name]

    • Compare the files in the workspace with the local library history
      Insert picture description here
  • Compare multiple files without file name
    Insert picture description here

3 Branch management

3.1 What is a branch?

In the version control process, multiple lines are used to advance multiple tasks at the same time.
Insert picture description here

3.2 Benefits of branching

  • Simultaneously promote the development of multiple functions in parallel to improve development efficiency
  • In the development process of each branch, if a branch fails to develop, it will not have any impact on other branches. Delete the failed branch and start again.

3.3 Branch operation

  • Create branch

    • git branch [branch name]
  • View branch

    • git branch -v
  • Switch branch

    • git checkout [branch name]
      Insert picture description here
  • Merge branch

    • The first step: switch to the branch that accepts the modification (to be merged, add new content) on
      git checkout [name of the merged branch]
    • Step 2: Execute the merge command
      git merge [Branch name with new content]Insert picture description here
  • Conflict resolution

    • Manifestations of conflict
      Insert picture description here
    • Conflict resolution
      • Step 1: Edit the file and delete special symbols
      • Step 2: Modify the file to a satisfactory level, save and exit
      • The third step: git add [file name]
      • The fourth step: git commit -m "log information"
        Note: At this time, the commit must not carry a specific file name
        Insert picture description here

Guess you like

Origin blog.csdn.net/Lu1048728731/article/details/115250776