Git use Daquan
- basic introduction
- git quick start
- Problems you may encounter
- reference
basic introduction
I have not started systematic learning when using git before. I only know simple git clone and push, pull binding public key, account creation and other introductory operations. For version control backtracking, .ignore filtering, multiple people collaborative development of merge, creation of dev and main development I am not familiar with the scene functions commonly used in work such as product branches, so I will record my advanced learning.
git quick start
I originally wanted to introduce git's remote warehouse and local warehouse upload first, but I was afraid that there would be too many rationales at the beginning and I was discouraged from doing so. So I'd better just get started and crawl through the code! It will be much easier to look back after learning how to use cv.
One environment installation (installed by default)
First of all, everyone has installed the git environment by default. If you haven't installed it, just search for a tutorial to install it. After installation, enter git in cmd and you will see this interface, which means success. There will also be git bash when you right click on the desktop
2. Clone the remote repository to the local one
There is an empty rep folder on the desktop. Now you need to clone the gitee remote repository into this folder.
1 Enter the rep folder directory
Right-click the directory and select Git Bash
to enter this interface.
2 Copy the remote warehouse address
3 git clone clones the contents of the warehouse to local
Enter git clone [warehouse address]
and if done 100% is displayed, the clone is successful.
View directory structure
Open the rep folder to view the changes. At this time, there is a git-learn folder under the folder, which is the cloned warehouse. Compared with the warehouse file structure, there is an additional .git folder.
The .git folder is the key to implementing version control. Please refer to the official documentation for specific details.
At this point you can happily change the code
4 Version control after modification
4.1 Modify files
Added a.txt file and write a.txt in the file
4.2 git status checks the status of repository files
git status indicates the modification status of the repository file
- 1 Status of newly added files
The following is a detailed translation of the instructions. Why do I need to translate them separately? Because beginners need to understand concepts such as version tracking, branches, remote warehouses, and commit at this time. There is no need to go into details here, just know that this thing exists. Before, I just knew how to use it without asking for a detailed explanation.
On branch master 表示在master分支
Your branch is up to date with 'origin/master'.
origin远程仓库下的master分支
Untracked files: 未进行版本追踪文件
(use "git add <file>..." to include in what will be committed)
使用“git add <file>...”包含要提交的内容
a.txt
nothing added to commit but untracked files present (use "git add" to track)
没有添加任何内容到提交,但存在未跟踪的文件(使用“git add”来跟踪)
Display a.txt in red, indicating that version control is not performed
4.3 git add adds files to the repository staging area
Use git add according to the prompts to add local files to the temporary storage area. Here is a brief explanation of the concept of the temporary storage area. Git version control is divided into remote warehouses and local warehouses. When we perform commit operations, we upload the files to the local warehouse first, and then Upload to remote repository.
In short, the staging area Stage establishes a mapping relationship between files and object entities in the .git/objects directory, and is just a simple index file. Refers to the .git/index file
- Pay attention to distinguishing the relationship between the staging area and the local warehouse
You can refer to the boss’s illustrations
Git command line operation with mind map https://zhuanlan.zhihu.com/p/362100222
Another big guy's diagram
Source: https://zhuanlan.zhihu.com/p/263050507
4.4 git commit -m "modification 1" saves the modification to the local warehouse
Using git commit directly will open the vm editor, which may be confusing to friends who are not familiar with it.
1 Press i to enter insert mode and enter the desired description on the first line.
2 Press Esc to exit insert mode
. 3 Enter: wq to save and exit
. 4 If you cannot exit, enter: wq! (! means force save and exit)
For more vm syntax, you can go to the official website to learn in depth.
Therefore, it is recommended for beginners to use git commit -m "修改信息"
the method to directly modify the information in the colon. -m means message.
Enter git status again to check the version control status. If nothing to commit is displayed, it means that version control has been carried out, indicating that there are no files for version control and the modifications have been submitted to the local warehouse.
4.5 git push push to remote warehouse
git push pushes modifications to the remote warehouse
so easy.
The picture below indicates that the push is successful.
git remote [option]
function: Set or read content related to the remote warehouse.
Use git remote -v to view remote warehouse information
View the changes in the remote warehouse.
You can see that a.txt has been added and the remark information is displayed.
Problems you may encounter
How to configure account information?
Since I have configured the gitee account information before, many friends may not have it, and an error will appear.
Search Credential Manager under the control panel to find the gitee account information, delete the account information,
modify a.txt and resubmit to see if there is an error.
git add .
"." indicates this directory and will automatically find modified files.
You can see that after commit, push will pop up an operation that requires me to enter the gitee account information. After entering the correct account and password,
it will show that the push is successful.
At this time, the credential manager will save the gitee account information for a long time, and I will not need to re-enter it after pushing! ! ! Awesome
About entering password (incorrect authentication information)
Enter the credential manager, modify the account information, and add anything to the account number or password. Push again and see if the error message
shows that the account or password is wrong. At this time, you only need to change it to the correct one.
Create a new account push
The corresponding scenario here is multi-user development. I want to create another account Alan with Local permissions locally and let him submit modifications to the local warehouse.
View warehouse statistics
Enter the warehouse/statistics and you can see that only one user submitted information.
Create a new user and push
git config -h again. View config
-h means help.
- Profile level:
- global user level
- system system level
- local project level
Here we use local to configure roles that are only valid for the current library, which is useful when using multiple roles in many libraries.
Set username and email address
Create a new user alan and resubmit the code. Because it has not been modified, nothing is submitted.
Switch users: git config --local user.name "xxx"
View user information
Edit a.txt and make the third modification
git push to the remote warehouse
Check the statistics of the remote warehouse.
At this time, the submission information added 'alan'.
I was a little dissatisfied with the two colons, so I changed it to alan. Because there were double quotes "alan" before, the user name was 'alan'.
Use the following command to modify the username and then view the username
git config --local --replace user.name 'alan'
git config user.name
Switch the account to, modify a.txt for the fourth time and then push
the git interface
to view the warehouse statistics.
The user of Mafei made the fourth submission
1 added
git config --local user.name ‘abc’
git config --local user.email ‘[email protected]’
2 modifications
(1) Form of coverage
git config --global user.name "yourName"
git config --global user.email "[email protected]"
(2) The form of replacement
git config --global --replace-all user.name "yourName"
git config --global --replace-all user.email "[email protected]"
3 Delete
git config --global --unset user.name "yourName"
git config --global --unset user.email "[email protected]"
4 view
(1) View all
git config --list
(2) View specified information
git config user.name
git config user.email
Three version control of local files after the remote warehouse is not created
Scenario: Created a local file, git did not create a warehouse
reference
1 图解Git操作,一篇就够 https://zhuanlan.zhihu.com/p/263050507
2 Git 命令行操作 https://zhuanlan.zhihu.com/p/362100222
3 添加、修改、删除以及查看本地git的用户名和邮箱 https://blog.csdn.net/womeng2009/article/details/101124910
4 【忽略文件版本控制gitignore详解,git-ignore精讲教程,2022年最新git基础使用,git进阶教程,git必备技能】 https://www.bilibili.com/video/BV1EG4y1Z7WW/?share_source=copy_web&vd_source=fe6c23f6f1353ed1eff5d5e866171572