Basic use of git client under windows
Git is a distributed file hosting system. Of course, the files here are mainly source code (text), and can also contain other non-text binary data. Since git is mainly used to store code (.java .c .cpp .h .jar .class…), we will use code to represent files in the future.
Git includes a complete client and server, and files are uploaded and downloaded through a secure communication protocol (HTTPS or SSH) between the client and the server.
1. git client download and installation
1.1 git client download: git client download
1.2 git client installation
Install git directly and default to the next step
. After the installation is successful, git will be added to the right mouse button by default.
2. Using the git client
2.1 Create a git repository
Here we test with the git server of the code cloud, and create a git warehouse on the code cloud. There are ji introductions in git configuration and basic use under ubuntu .
Reference link: https://blog.csdn.net/weixin_44453694/article/details/123999289
2.2 Local warehouse initialization and setting global name and mailbox
Here is an example of a picture processing project of STM32.
git init //初始化本地仓库
git config --global user.name "it-a-shui" //设置全局用户名
git config --global user.email "[email protected]" //设邮箱
git config --list //查看配置信息
2.3 Associate remote repository and code submission
Associated warehouse: git remote add <remote warehouse alias> <remote warehouse address>
add origin -- remote warehouse alias, the name can be filled in at will
https://gitee.com/it-a-shui/stm3s-cqde-test.git - - Remote warehouse address
git remote add origin https://gitee.com/it-a-shui/stm3s-cqde-test.git
git add -A //添加本地所有文件到
git commit -m "第一次代码提交测试"
git push --set-upstream origin master //提交代码到服务器
Bug fix:
git pull is used to fetch from another repository or local branch and integrate (integrate)
git pull --rebase origin master //将本地仓库和远程参考统一
git push --set-upstream origin master //再次提交
Of course, we can also force a commit:
git push -u wbyq +master pushes all the contents of the local warehouse branch wbyq branch to the master warehouse (generally not recommended).
At this point, the local warehouse has been successfully created and associated, and subsequent submissions only require one command.
git add <要添加的文件> //git add -A 表示本地所有文件
git commit -m "提交说明"
git push //提交到远程仓库
2.4 Clone files
git clone <repository address>
git clone https://gitee.com/Matreshka15/USV-STM32F103-part.git
2.5 View the commit log and version rollback
Refer to the commit log: git log
version rollback: git reset --hard <version number>
$ git log
commit 254ccee15a331f4987fffd2343db996e2d205b35 (HEAD -> master, origin/master)
Author: it-a-shui <it-a-shui@872561012@qq.com>
Date: Tue Apr 12 17:35:33 2022 +0800
修改main.c文件
commit efb8a3fadc23607a3c55d0831c64505c196cff32
Author: it-a-shui <it-a-shui@872561012@qq.com>
Date: Tue Apr 12 17:00:12 2022 +0800
第一次代码提交测试
commit ed4ba9182f699cd038057e783f699bd375b1ebc5
Author: it_阿水 <872561012@qq.com>
Date: Tue Apr 12 08:33:21 2022 +0000
Initial commit
$ git reset --hard efb8a3fadc23607a3c55d0831c64505c196cff32
HEAD is now at efb8a3f 第一次代码提交测试