Git
多图预警
一、Vscode + Github 克隆和同步
可以使用vscode和github进行协同工作,
开始的时候有以下几种模式:
- 将本地文件夹初始化为给本地git仓库,在github上新建仓库,将本地的仓库推送到远程仓库
- 如果想要将本地文件夹同步到已经存在且有数据的远程仓库中,建议先将本地文件上传到github,再使用vscode进行克隆,然后修改,然后推送
上传—克隆的模式的操作更为复杂,详细步骤如下:
1、选择克隆存储库
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F10eff799-84a8-43fb-be66-f3ac1edc24fa%2FUntitled.png?table=block&id=a6b055b2-6232-4e72-a4f6-4bcc88ede197&cache=v2)
2、如果是第一次,则需要github授权
3、授权完成再点击克隆存储库,会出现弹窗,可以选择需要克隆的仓库
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Feea2921d-e2c0-4f39-997c-b19d35f16d4f%2FUntitled.png?table=block&id=61b68da7-8e76-4e73-a21e-7ad24b755514&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F0d16bd48-e2ad-484c-a03d-03f5acc3ea02%2FUntitled.png?table=block&id=bf5dd473-7eac-4654-8e00-3e5b914fa8a7&cache=v2)
4、选择然后克隆就可以了。
使用vscode将代码同步到远程
1、在对本地仓库进行更改之后会查看到提示,第一步需要将本地更改提交到暂存区
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F9b4ba1f1-bde2-454a-932d-74a239d71950%2FUntitled.png?table=block&id=8f3699c8-3502-4588-bf1e-b5746b8ea311&cache=v2)
2、将暂存区的更改提交到本地版本库(master)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F5a46caa0-0733-4c0c-814f-c6da88c4679d%2FUntitled.png?table=block&id=41a44e4f-432b-4a8d-9a8a-05ca88dad3a3&cache=v2)
3、将本地修改同步到GitHub
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F64bf8524-c0a4-4cd5-aaa3-30803bb24acf%2FUntitled.png?table=block&id=23427960-f255-40e3-a14f-6d347338e9db&cache=v2)
可能会遇到的问题:遇到这些问题可能是公司网络问题
推荐阅读:
1、Failed to connect to github.com port 443:connection timed out
## 取消代理——解决问题 git config --global --unset http.proxy git config --global --unset https.proxy
# 增加代理 git config --global http.proxy http://127.0.0.1:1080 git config --global https.proxy http://127.0.0.1:1080
2、Git: fatal: unable to access 'https://github.com/.git/': LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
网络问题,连不上github,当前网络限制访问github导致的报错原因;
多试几次
3、Git: fatal: unable to access 'https://github.com/anjhon1994/My_tools.git/': Failed to connect to github.com port 443 after 75062 ms: Operation timed out
git使用的网络端口不是VPN的端口,将git端口设置为vpn端口
# 查看代理 git config --global -l # 取消设置代理 git config --global --unset http.proxy git config --global --unset https.proxy # 设置代理 git config --global http.proxy http://127.0.0.1:7890 git config --global https.proxy https://127.0.0.1:7890 # 强行推送(覆盖)————在新增文件或其他时候 # 无法推送 refs 到远端。您可以试着运行“拉取”功能,整合您的更改。 git push origin master -f
二、GitHubDesktop + Vscode解决代码冲突
1、先使用GitHubDesktop克隆fork后的仓库到本地
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F594049eb-68ec-4be8-85fd-022a4b201d0d%2FUntitled.png?table=block&id=bdd081b1-6857-4671-91eb-0f636b9b205a&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fd8e05ed6-fbc2-4d53-b4ad-3c77744f70e9%2FUntitled.png?table=block&id=578ceb9e-086a-43ba-bf93-a55155111aed&cache=v2)
2、选择原仓库的想要更新的版本,合并到自fork后的仓库
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F2d83d5d0-c30f-4c16-b3bb-762d68cd6aed%2FUntitled.png?table=block&id=7aea1183-9031-446e-bf7f-db3bac6b3662&cache=v2)
选择上游仓库源的版本(这里选择 tangly1024.com 的deploy 版本), 显示有两个文件冲突了,点击
create a merge commit
创建合并提交.![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F52d0ef6b-0942-4623-bc0e-c4eb1b546005%2FUntitled.png?table=block&id=fb24af3b-c46d-4ab3-b5b7-4e716f83f30e&cache=v2)
3、如果是整个文件都被修改了(文件名相同但内容不同,如相同名称的图片)会询问是使用哪个分支的提交;,
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F2f1de0bb-81ef-4645-b517-f8f1b31b4be7%2FUntitled.png?table=block&id=9906b7ae-359f-41c2-a880-c283e0efa1e8&cache=v2)
4、如果是代码文件的内容有冲突,则会提示在你的默认编辑器中进行手动合并;
或者也可以点击下拉框直接选择使用哪一个仓库的同名文件(强烈不建议,因为文件内部如果有代码冲突的话,说明有内容更新,如果直接使用自己仓库的文件整体去覆盖,就相当于忽略了代码冲突,会导致后续部署出错; 当然如果文件自己没有改动,但是更新是还是有冲突,那就说明是上游作者修改了文件,这时候可以用新文件覆盖旧文件)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F56740063-10ad-439c-bf1e-fc7ae147df4d%2FUntitled.png?table=block&id=0fb93f92-301e-4288-9df8-11bfcabc35fc&cache=v2)
5、解决冲突
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F8b436bd9-e21b-4bc4-9a1a-333708e17c47%2FUntitled.png?table=block&id=b60a6ac3-8148-4271-8589-d8c72b5f1e6d&cache=v2)
6、将修改好的本地版本同步到GitHub
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F1ee109a4-fbca-439e-97c9-6d46f937ece4%2FUntitled.png?table=block&id=e908222c-de50-40d7-a806-28d9b095f83e&cache=v2)