Git

Git local libraries interact with remote libraries

  1. Git native structure

  1. Intra-team collaboration

  1. Working across teams

  1. Classification of Hosting centers

    1. In the LAN environment: Gitlab server can be set up as a code hosting center, and Gitlab can set up by itself
    2. In the external environment: You can have GitHub or Gitee as the code hosting center. GitHub or Gitee is a ready-made hosting center, so you don’t have to build it yourself

Initialize the local repository

  1. Check the local repository: git –version

  2. CLS: clear

  3. Set the user name and email address

    1. Git config --global user.name git config --global user.name
    2. Git config --global user.email
  4. Initialization of a local repository: git init

  5. ./git files do not touch

Git git

Add and commit commands

  1. Create a file
  2. To submit a document to the staging area:git add Demo.txt
  3. To commit the contents of the staging area to the local library:Git commit -m "commit first file demo.txt

The status command

Git status Displays the status of the workspace and staging area

  1. Red is the file that the workspace has not committed to the staging area
  2. Green are files that the register has not committed to the local library
  1. Modify the demo.txt file againgit statusGit will tell you that you have files that need to be updated and re-executedaddcommitCommand to update the file to the local library

The log command

View the commit record and display the log from near to far

  1. Mention too many records, not a page show, paging effect

    1. Next page: Space
    2. B
    3. At the END of the page, END is displayed at the bottom
    4. Exit: q
  2. Several ways to view commit records

  3. git log

  4. git log --pretty=oneline

  1. git log --online

  1. git reflog

    1. thangit log --onelineHEAD@{number}
    2. The number represents the number of steps needed to get the pointer back to the current version

The reset command

Forward or backward history version

  1. Git reset-- set the hash value of the back version

  2. Copy: Select the terminal to copy

  3. Paste: Right click paste

  4. Three parameters of reset

    1. --hardAs the local library pointer moves, the staging area and workspace versions change
    2. --mixedAs the local library pointer moves, the staging version changes, but the workspace version stays the same
    3. --softWhen the local library pointer moves, the staging area and workspace versions remain the same

Rm deleted the workspace file and reset restored the file

  1. Delete the file

    1. rm test.txtDelete the file named test. TXT from the workspace
    2. git add test.txt: Synchronizes the delete operation to the staging area
    3. Git commit -m 'delete text.txt file' test.txt: Synchronizes the delete operation to the local library
  2. Recovering deleted Files

    1. Git reset -- hashes of the hard version: Restores deleted files
    2. Tip: You can also use this method if you have deleted a file in your workspace and have synchronized the deletion to the staging area. The effect is equivalent to undoing the deletion

diff

  1. git diff: Compares all file differences between workspace and staging
  2. Git diff file name: Compares the file contents of the corresponding file names in the workspace and the staging area
  3. Git diff hash file name: Compares the difference between the staging area and the corresponding file name content of the hash local library

branch

What is a branch

  1. In version control, multiple lines are used to advance multiple tasks at the same time. By multiple lines, we mean multiple branches

  2. The branches are shown in a diagram

  1. Benefits of branching:

    1. At the same time, multiple branches can be developed in parallel, without delay or influence each other, so as to improve development efficiency
    2. If a branch fails to be developed, it can be deleted without any impact on the other branches

Operating branch

  1. git branch -v: View branches
  2. git branch branch01: Creates a branch named branch01
  3. git checkout branch01: Switch to the branch named branch01

Merging branches

Merge branch01 into the master branch

  1. Git checkout master: Switch to the master branch

  2. Git merge branch01: merge branch01 into master branch

  1. Error: cat test4.txt error: cat test4.txt error: cat test4.txt error: cat test4.txt

  2. Conflict resolution:

    1. Decide on conflicting files, which plan to use, and delete unwanted files
    2. git add Test4.txt: Submits to the staging area
    3. Git commit test4.txt -m: Commit to local library (note: do not write file name, otherwise error!)

GitHub

The basic use

  1. GitHub creates a project

  2. Create a local library locally

  3. Get the path in Code

  4. Git remote -v: Displays the alias list

  5. Git remote add origin github project address: Create an alias name for the project address named origin

  6. Git push origin master: commit the origin master file to the remote repository

  7. Git clone Remote repository location: Clone files from the remote repository to the local directory

    1. Git checkout origin/ git checkout name: Toggles remote library branches
    2. The cat filename: Displays file information
  8. Pull and merge remote library operations

    1. The programmer made changes to the remote library that the product manager could pass throughgit fetch origin masterFetching operation, only the contents of the remote library are downloaded locally, the contents in the workspace are not updated,
    2. After fetching, you can go to the remote library to see if the content is correct
    3. And then found out that everything was correct,git merge origin/masterYou can merge (switch branches back before merging)
    4. The pull and merge operations can be replaced by a single operation:git pull origin maste
  9. If other programmers want to submit files to the remote library, they need to make a membership invitation

    1. Enter the name of the member in setting to invite the member
    2. Copy invite link
    3. Link the invitation to the person you want to invite
    4. The person invited receives the membership invitation via this link
  10. Co-development conflicts occur when two programmers modify the same file in the same branch at the same time

    1. git pull origin master: Pulls files to local libraries and workspaces
    2. Artificial conflict resolution
    3. Commit the two tracks to the local library.
    4. git push origin master: Commits to the remote repository
  11. Working across teams

    1. Get the GitHub address of the project
    2. Enter the account, copy the address, and click fork
    3. Git clone GitHub address: Clone to a local computer
    4. Write function
    5. Commit files from the local library to the remote library
    6. Do the Pull requests operation

SSH Encryption-free login

  1. Go to the user home directory

    1. cd ~
  2. Run the command to generate the ssh. directory

    1. Ssh-keygen -t Rsa-c email address
  3. We found two extra files in the home directory.ssh

    1. Let’s open the file with the suffix.pub and copy everything inside
    2. Go to your Github account,
    3. In setting SSH and GPG keys paste the copied object and name it
  4. Git remote add origin_ssh git remote add origin_ssh

  5. Git push origin_ssh master commit files from master branch to origin_ssh remote repository