git/README.md
2024-11-12 23:53:52 +08:00

55 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用 VS Code 进行 Git 操作的教程
为了更好地使用 Git下面是一篇通过 VS Code 使用 Git 的教程(基础操作,仅包含创建和提交)。
关于如何配置 SSH 请参考文章:[如何配置 SSH](https://qutcmrt.top/index.php/archives/195/)
## 第一步:安装 Git 插件
在扩展里搜索 Git安装以下三个插件
- Git Graph
- Git History
- GitLens
这些插件非常好用,可以帮助你更直观地查看 Git 历史、分支和提交记录。
![安装插件](https://qutcmrt.top/usr/uploads/2024/11/1784299241.png)
## 第二步:创建仓库
创建一个工程之后,用 VS Code 打开工程,进入源代码管理器,点击第一个初始化仓库按钮。
![创建仓库](https://qutcmrt.top/usr/uploads/2024/11/1658756132.png)
## 第三步:提交代码
在进行代码提交之前,先为这次提交取一个名字,然后点击提交按钮。
![提交代码](https://qutcmrt.top/usr/uploads/2024/11/1065970515.png)
提交之后,你可以查看每个版本的修改记录,并且可以随时切换到以前的版本。
## 第四步:添加远程仓库
这里使用青理机器人战队的官方 Gitea 为例。
1. 登录 Gitea创建仓库填写仓库名称。
![创建远程仓库](https://qutcmrt.top/usr/uploads/2024/11/1450812280.png)
2. 创建之后,进入仓库,此时仓库还没有任何内容。根据提示内容链接远程仓库。
![链接远程仓库](https://qutcmrt.top/usr/uploads/2024/11/2615099837.png)
由于我们已经在本地创建了仓库,所以只需要执行以下步骤:
```sh
git remote add origin ssh://git@gitea.qutcmrt.top:222/Robofish/git.git
git push -u origin main
```
![推送代码](https://qutcmrt.top/usr/uploads/2024/11/1041488949.png)
成功创建远程仓库!之后进入 Gitea 即可分享和下载代码。
![成功创建](https://qutcmrt.top/usr/uploads/2024/11/4003579224.png)