This is the second day of my participation in the November Gwen Challenge. Check out the details: the last Gwen Challenge 2021

Git structure

Git command line operation

2.1 Local Library initialization

1. The command:

git init

2. Steps & Results:

  • First go to the project directory with the CD command
  • Run the git init command
  • Create a.git hidden file (do not modify this file)

2.2 Setting a Signature

  1. In the form of
User name: Tom Email address: [email protected]Copy the code
  1. What it does: Distinguish the identities of different developers
  2. The signature set here has nothing to do with the password used to log in to the remote repository (GitHub)
  3. The command
    1. Project level/repository level: valid only within the scope of the current local library
      • The command
      git config user.name tom_pro
      git config user.email [email protected]
      Copy the code
      • Git /config file./.git/config file
    2. System User level: specifies the user level for logging in to the current operating system
      • The command
      git config --global user.name tom_glb
      git config --global [email protected]
      Copy the code
      • Information save location: ~/. Gitconfig file
    3. Level Priority
      • Proximity rule: Project level takes precedence over user level, and both sometimes use project-level signatures
      • If only the signature of the system user level is available, the signature of the system user level prevails
      • You can’t have both

2.3 Basic Operations

  1. Status View operation
Git status // Check the status of the workspace and staging areaCopy the code
  1. add
Git add[file name] // Add new/Modify from the workspace to the staging areaCopy the code
  1. submit
Git commit -m "explain message" [file name] // Add the contents of the staging area to the local libraryCopy the code
  1. Viewing History
    1. A complete view
      • The command
      git log
      Copy the code
      • The effect

    2. Single row shows
      • The command
      git log --pretty=oneline
      Copy the code
      • The effect

    3. Simple single-line display
      • The command
      git log --oneline
      Copy the code
      • The effect

    4. Steps show
      • The command
      git reflog
      Copy the code
      • The effect

      • Note:

      HEAD@{how many steps to move to current version}

  2. Move back
    1. Git has a HEAD pointer to the current version of git. Each version of Git in history is recorded with an identity, distinguished by the HEAD pointer

    2. Perform operations based on index values

    • Start by looking at all index values with git reflog
    • The fallback command
    Git reset --hard[9994d43]Copy the code
    1. Use ^ symbol: only backward
      Git reset --hard HEAD^ //Copy the code
    2. Use the ~ symbol: only back
      Git reset hard HEAD~n //Copy the code
  3. Comparison of three parameters of the reset command
    1. Soft parameter
      • Move the HEAD pointer only in the local library
      • Explanation:The contents of the workspace and the staging area are the same, and the local library is rolled back to the previous version, so the staging area shows the uncommitted state
    2. Mixed parameter
      • Move the HEAD pointer in the local library
      • Reset the staging area
      • Explanation:The workspace contents remain the same, while the local libraries and staging areas are back to their previous versions, so the workspace appears unadded
    3. Hard parameters
      • Move the HEAD pointer in the local library
      • Reset the staging area
      • Resetting the workspace
      • Explanation:Now all the contents of the three areas are the same, but all revert back to the previous version
  4. Delete files and retrieve them
    1. Prerequisite: The file has already been committed to the local library before deletion
    2. operation
    Git reset --hardCopy the code
    • The delete operation has been committed to the local library: the pointer position points to the history record
      Git commit -m "new apple.txt" apple.txt Rm apple. TXT git add apple. TXT git commit -m "delete apple. TXT "apple. TXT git reset -- Hard [hash value of the version to be restored]Copy the code
    • The delete operation has not been committed to the local library
      Git reset --hard HEADCopy the code
  5. Compare file differences
    1. Compare the files in the workspace with the staging area
      Git diff[filename]Copy the code
    2. Compares workspace files with local library historical versions
      Git diff[^,~][filename]Copy the code
    3. All files can be compared without file names
      Git diff HEAD git diff HEADCopy the code

2.4 branch

  1. What is a branch
    1. In version control, multiple lines are used to advance multiple tasks simultaneously
      • Feature_blue and Feature_game are new additions to the feature_game.
      • Merge operations after development is complete. Merge to master branch, equivalent to version iteration.
      • Hot_fix indicates that a bug occurs on the master. Copy the master to hot_fix and merge the hot_fix to the master

2. Benefits of branching

  1. Promote the development of multiple functions at the same time, improve the development efficiency
  2. During the development of each branch, the failure of one branch has no impact on other branches. Delete the failed branch and start again.
  3. Branch operation
    1. Create a branch
    Git branchCopy the code
    1. See the branch
    git branch -v
    Copy the code
    1. Switch branch
    Git checkoutCopy the code
    1. Merge branches (without conflicts)
    • Step 1: Switch to the branch that accepts the change
    Git checkout[branch name to accept changes]Copy the code
    • Step 2: Run the merge command
    Git merge[branch name with new content]Copy the code
    1. Resolve the conflict
      • Expression of conflict

      Conflicting files will display all the contents of the two conflicting files, edit your own

– Conflict resolution – First step: edit the file, delete the special symbols – second step: modify the file to a satisfactory degree, save and exit – third step:Git add– Step 4:Git commit -m– Note: Commit must not carry a specific file name

Third, making

3.1 Creating a remote library alias

  1. grammar
Git remote add[alias][remote address] git remote add[alias]Copy the code
  1. The effect

3.2 push

  1. grammar
Git push[alias][branch name] // The alias obtained from the previous step, upload the branch you want to uploadCopy the code
  1. The effect

3.3 the cloning

  1. The command
Git clone[Remote Address] // The remote address is the same as the address in 3.1 Obtaining an AliasCopy the code
  1. The effect

3. The role

  • Download the complete remote library to the local
  • Automatically create a remote library alias
  • Initialize the local library

3.4 Invitation of team members

3.5 pull

  1. explain:
    • Someone else pushes the remote library after making changes to the file.
    • This is where you need to pull down the contents of the remote library.
    • The pull operation can be split into two parts: FETCH and merge. Merge is divided into conflicting and non-conflicting types
  2. grammar
// The first type (pull in two steps, Git pull[remote address alias][remote branch name] //pull = fetch + mergeCopy the code
  1. Conflict resolution
    • If the changes are not based on the latest version of the GitHub remote library, they cannot be pushed and must be pulled first
    • If a conflict occurs after being pulled down, resolve the conflict according to “Branch Conflict Resolution”