Git entry study notes

Git study notes:

1. What is Git?
Git is currently the most popular distributed version control system in the world.

2. The main difference between SVN and Git:
SVN is a centralized version control system, and the version library is centralized on the central server, that is, a computer. Developers use their own computers during the development process, so they must first download the latest version from the central server, and then develop. After completion, they need to push their own modified results to the server. However, it must be connected to the Internet to work. The speed of the network affects the development efficiency of the project. If the network is disconnected and the code cannot be submitted, the project may be at a standstill.
Git is a distributed version control system. It does not have a central server. Everyone’s computer has a complete library. It does not need to be connected to the Internet when working. You can submit the modified results to the local version library. After the network is available, it will be modified. push. Distributed version control systems usually also have a computer that acts as a central server. This server is only used to facilitate the exchange of everyone's modifications. Without it, everyone can work normally, but the modification is inconvenient. The distributed version control system client does not only extract the latest version of the file snapshot, but completely mirrors the code warehouse, including the complete historical record. In this way, if any server used for collaborative work fails, it can be restored with any mirrored local warehouse afterwards. Because every clone operation is actually a complete backup of the code warehouse

3. Remote warehouse
The remote warehouse is to find a computer to act as a server, and turn it on 24 hours a day. Everyone can transfer the items needed by the server warehouse to their computers, and push their submissions to the server warehouse. It is possible to pull other people's submissions from the server repository.

4. Git installation
Download the latest version of Git from the official website, and then install it.
Official website: https://git-scm.com/downloads
Find Git Bash in the start menu and run it. A command box will pop up, indicating that the installation is successful.
insert image description here
After the installation is complete, you need to set the user name and email address, because Git is a distributed version control system, which requires the user name and email address as an identifier.

Set command:
set username (global):
git config --global user.name ”yourname”
set mailbox (global):
git config --global user.email ”youremali@x'x'x”

Set the username and email address for a project individually

 git config user.name “yourname”
 git config user.email “youremail@xxx”

5. Git uses (command)
version library, also known as warehouse, which can be simply understood as a directory. All files in this directory can be managed by Git. Git can track the modification and deletion of each file, so that at any time History can be tracked, or the file can be "reverted" at some point in the future.

Exercises of Git commands:
Create a version library
1, git init xxxor cd xxx git init(initialize a version library)
change the current directory to a directory managed by git, and a .git directory (git tracking management version) will be generated under this directory.
insert image description here

2. git add <file>Add the file to the temporary storage area

3. git commit -m ”注释”Submit the double quotes behind it is the submission remarks
insert image description here

View status
4. git statusView the current file status

5. git diff <file>View the modified content of the file
After modifying the demo.txt file, check the status of the file to show that it has been modified. Use the git diff demo.txt command to view the modified content of the file, where + means new, - means deleted.
insert image description here

6. cat <name>View the contents of the file corresponding to the name

Version rollback
7. git lotDisplay the commit log from the nearest to the furthest.
Modify the demo.txt file twice
1. Add 11111111111111111 and submit 2. Add 22222222222222222 and submit

Short version:git lot --pretty=oneline
insert image description here

HEAD points to the current version, switch between version departure records
8, git reset --hard HEAD^return to the previous version ,
git reset --hard HEAD^^return to the previous version,
git reset --hard HEAD~xreturn to the latest xth version
insert image description here

9. git reflogReturn to the past to view the command history
10. git diff HEAD --<file>View the difference between the version in the work area and the latest version in the version library
11. rm <file>Delete the file file

12. git checkout -- <file>Restore files

Branch management
Create a new branch
13. git checkout -b <name>Create and switch branches.
The above can be divided into two parts: create a branch and switch branches
git branch proCreate a pro branch
git checkout proSwitch to a pro branch
git branch -d<name>Delete
all changes submitted on the new branch will not affect other branches, will not change other Any content of the branch can be merged into the master branch after all the work on the new branch is completed.
14. git branchView all current branches. There will be an * number in front of the current branch.
15. After switching to the master branch, merge the branch
git mergequickly. Merge

Associate the remote warehouse
16. git remote add origin http://github.com/xxx.gitAssociate the local library with the remote library
17. git push -u orgin <name>When pushing for the first time, specify which branch to push to
18. git push origin masterAfter the first push, use this command to push directly later

19. git clone http://github.com/Promote96/xxx.gitUse git to clone the project

Note:
If ">" appears in the command line and cannot exit, it is because the input command is incomplete, use ctrl + D to return

Guess you like

Origin blog.csdn.net/weixin_40307206/article/details/107426841