[AI Creation] Articles Written with AI Creation Assistant--Question Git Series

insert image description here

Explains the basic concepts of Git and how to use it.

Git is a distributed version control system that manages file versions by recording file changes, can save file history, and supports multi-person collaborative development.

The following are the basic concepts and usage of Git:

  1. Repository: The Git repository is where the code is stored, which can be understood as a folder. Git supports local warehouses and remote warehouses. The local warehouse is stored on the local computer, while the remote warehouse is stored on the remote server.
  2. Branch (Branch): Git allows development on multiple branches at the same time, and these branches can be developed independently of each other without affecting each other. The main branch is generally the master branch, and other branches can be created and merged as needed.
  3. Commit: In Git, commit refers to saving the modified file to the local warehouse. Each submission will record the modified content and submission information.
  4. Merge (Merge): When the modification on one branch reaches a mergeable state, it can be merged with another branch. Merging is combining changes from two branches to form a new commit.
  5. Push (Push): After the code is submitted in the local warehouse, it needs to be pushed to the remote warehouse. By pushing, other developers can see and use these changes.
  6. Pull (Pull): During multi-person collaborative development, in order to obtain the latest code, you can pull the code from the remote warehouse to the local warehouse.

Git is used as follows:

  1. Install Git: You can download and install Git from the Git official website.

  2. Create a local repository: You can use the Git init command to create a new Git repository.

  3. Add files: use the Git add command to add the files to be submitted to the local warehouse.

  4. Submitting files: use the Git commit command to save the modified files to the local warehouse, and add submission information.

  5. Push code: Use the Git push command to push the local code to the remote warehouse.

  6. Pull code: Use the Git pull command to pull the latest code from the remote warehouse to the local warehouse.

  7. Branch management: You can use the Git branch command to create, switch, and merge branches.

  8. View history: Use the Git log command to view the commit history of the local warehouse.

In short, Git is a very powerful version control system that can effectively manage code versions and history, and is suitable for personal development and multi-person collaborative development.

What are the common commands of git?

The following are commonly used commands for Git:

  1. git init: Create a new warehouse.
  2. git add: Add files to the temporary storage area.
  3. git commit: Submit the changes in the temporary storage area to the local warehouse.
  4. git clone: ​​clone an existing warehouse to the local.
  5. git fetch: Get the latest updates from the remote warehouse, not automatically merged into the local warehouse.
  6. git pull: Get the latest update from the remote repository and merge it into the local repository.
  7. git push: Push the changes in the local warehouse to the remote warehouse.
  8. git status: View the status of the current warehouse, displaying unadded and modified files, etc.
  9. git log: view the commit history.
  10. git branch: create, modify and delete branches.
  11. git merge: Merge two or more branches.
  12. git diff: View the differences of file changes.
  13. git tag: Label the version.
  14. git checkout: Switch branches or restore files to previous versions.
  15. git stash: temporarily store the current working directory for switching branches or fixing bugs.

git exception error solution

There may be many reasons why Git reports an error, and you can locate the problem and solve it according to the specific error prompt. Here are some common Git exceptions and their solutions:

  1. Git clone 报错:error: RPC failed;curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

This error is usually caused by a network problem or a busy GitHub server. You can try the following methods to solve the problem:

  • Check whether the network connection is normal, there may be restrictions on the network, you can try using a VPN
  • Try to clone using the SSH protocol, the SSH protocol is fast and stable
  • Enable the compression function of Git to reduce the amount of data transmission, command: git config --global core.compression 1
  1. Git push 报错:! [rejected] master -> master (fetch first)

This error is usually due to a conflict between the local warehouse and the remote warehouse, and a merge operation is required. It can be solved by using the following command:

  • git pull origin master
  • git merge origin/master
  • git push origin master

If there are conflicts, you need to manually resolve the conflicts before merging.

  1. Git checkout 报错:error: Your local changes to the following files would be overwritten by checkout

This error is usually caused by the local folder being out of sync with the Git repository. It can be solved by using the following command:

  • git stash: temporarily store local modifications
  • git checkout : switch to other branches
  • git stash apply: restore local modifications
  1. Git commit 报错:error: failed to push some refs to

This error is usually due to the difference between the local warehouse and the remote warehouse, and the Pull operation needs to be performed first. It can be solved by using the following command:

  • git pull origin : Pull the latest code
  • git add .: Add the modified file to the temporary storage area
  • git commit -m "commit message": Submit local modifications
  • git push origin : Push local changes to the remote warehouse

These are common Git error reporting situations and their solutions, but the actual situation may be more complicated, and specific problems need to be analyzed in detail, and corresponding solutions can be found through search engines.

at last

Remember to pay attention to me, let's communicate and make progress together

Guess you like

Origin blog.csdn.net/leng_yong/article/details/130881146