Table of contents
注意:请详细看4.3存在冲突那里
1. How to submit code
1.1 git status
Check if there is any modification, the red modified modified file will be displayed.
If it is not displayed, it means that you have not modified or added any code currently.
1.2 git add .
git add . Indicates that all files in the current directory are added to the temporary storage area. You
can use the command git status to view. Green files indicate that they have been added to the temporary storage area, and modifiled indicates that you have modified files
1.3 git commit
Git commit means adding the contents of the temporary storage area to the local warehouse
Generally, when submitting code to your own warehouse, you can directly use git commit -m to "remark the information you submitted the code" , but in the company, you usually have your own template
1.3.1 How to create a commit template
In the company, there is usually a commit template. How to create a commit template?
- Create a commit template
Create a new text document, copy the following content into it, save it, and rename it to committemplate
#type feat:
#<specific description>
#<problem number>
# type field contains:
# feat: new function (feature)
# fix: fix bug
# docs: documentation (documentation)
# style: format (does not affect code operation change)
# test: add tests
# chore: changes in the build process or auxiliary tools
# subject: a brief description of the purpose of the commit, no more than 50 characters
- Set the template path, where path is the commit template path (the path separator uses
/
or\\
)
git config --global commit.template path
- Set what software to use to open the template, generally use Notepad [notepad]
git config --global core.editor [编辑器名字]
注意
: path use \
instead of /
, or escape //
with/
This window will pop up when git commit is performed, and the description of this code submission can be made, and ctrl+s can be saved
1.4 git pull --rebase
git pull means to pull the remote code and update our warehouse
1.4.1 Why add --rebase?
Click: Please see here → there is a detailed explanation
1.4.2 If there is no conflict, just push directly
If after git pull --rebase is finished, it finally displays: Successfully rebased and updated xxx or Current branch xxx is up to date , which means that there is no conflict between the code you submitted and the remote warehouse, and you can just push it directly.
Successfully rebased and updated xxx means: the latest submission of the warehouse was submitted by others, but there is no conflict, just push it directly
Current branch xxx is up to date means: the latest submission of the warehouse was submitted by you, just push it directly
1.4.3 If there is a conflict (git rebase --continue)
If there is a conflict, it will display some prompt information such as CONFLICT merge conflict and hint.
Then you open your QT project again, and there will be information such as <<<< and ==== in the code, indicating that there is a conflict in the code, and you need to to resolve conflicts
(1) It is strongly recommended to use VS Code
It is strongly recommended to use VS Code here, it is really convenient, it can clearly mark the difference between two conflicting files (the pulled file and the file you modified locally), and the code difference
(2) After the conflict is resolved and the project runs successfully, continue to execute the following command
git add .
git rebase --continue
( Successfully rebased and updated xxx will appear after execution )git pull --rebase
(In order to avoid other people submitting code during conflict resolution, this command must be executed before push)- Until it appears: Current branch xxx is up to date ., you can push; if it does not appear, it means that there is still a conflict, and you need to continue to resolve the conflict
(3) Why do you need to perform a git pull --rebase before pushing?
- Because during the period when you resolve the conflict, you don't know if anyone else has submitted code to the warehouse.
- If you have a short time to resolve the conflict and no one has submitted code during the period, you can push directly.
- If your conflict resolution event is relatively long, and someone submits code to the warehouse during the period, an error will occur after you resolve the conflict and then push, because your local code at this moment is inconsistent with the code in the remote warehouse.
- Therefore, for safety reasons, it is best to perform a pull operation before push.
1.5 git push
git push means to upload the local branch version to the remote warehouse and merge it
Well, you're done! ! !
2. How to pull the code
The first thing to do when you come to the company every morning is to pull the code
First execute the git status command to check if the code has been modified
2.1 If the code has not been modified locally
Check if you have modified the code. If you have not modified the code (the red modified file is not displayed ), you can directly pull the code
2.2 If the code has been modified locally
Check if you have modified the code. If you have modified it, you cannot directly pull the code, otherwise an error will occur.
The correct way is: first temporarily store your current code, and then apply it after pulling the code. The specific command is as follows:
2.2.1 git stash
Save your current modified code. For
specific stash commands, click here → very detailed
2.2.2 git status
At this time, the red modified file will not be displayed, and it will display Already up to date. You can pull it directly
2.2.3 git pull
At this time, the remote code has been pulled to your own local
2.2.4 git stash apply or git stash pop
Apply the previously stored code to the local
difference between git stash apply and git stash pop→click here
Well, you're done! ! !