CI/CD-分布式版本控制系统-gitlab仓库代码管理实践
部署实战架构图
halo源码下载
- 下载源码
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop
$ git clone https://github.com/halo-dev/halo.git
Cloning into 'halo'...
remote: Enumerating objects: 92962, done.
remote: Counting objects: 100% (632/632), done.
remote: Compressing objects: 100% (457/457), done.
remote: Total 92962 (delta 400), reused 316 (delta 122), pack-reused 92330
Receiving objects: 100% (92962/92962), 71.46 MiB | 10.11 MiB/s, done.
Resolving deltas: 100% (52395/52395), done.
Updating files: 100% (2312/2312), done.
- 关联gitlab仓库
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop/halo (main)
$ git remote remove origin
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop/halo (main)
$ git remote -v
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop/halo (main)
$ git remote add origin git@116.62.138.9:linux0224/my_halo.git
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop/halo (main)
$ git remote -v
origin git@116.62.138.9:linux0224/my_halo.git (fetch)
origin git@116.62.138.9:linux0224/my_halo.git (push)
## gitlab ssh_key配置
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop/halo (main)
$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCPn30rXrR87cldP4RYjVzmGNd1AdRcdBd7UV5hvabAYCBEBOO8Aaf9F3j7c4jvuonv8bn/v1PcLh7jYvxpSxafJzRMZepjgrt9sdTMvjZzIrm6Lfb5Re8J9NwvKs/ZQwxKR3/oVQpf+CQzfFNTT+LxMJT0OCz9feHL8Ala+kif9Tn10aiuU6cDrkZllHFJC313zRAgHXuAW8mEL4VVr5EaggopYEA0afVL1SQXo7xiSj4YkgkLip1vB9veZ+pym46vq768JpDiS72Lo59DstTlKZ8TIR0S3lpsQpbuHCrDn4LlJSEBMQERhlivfSsRA3TjhzVV2QtZOz90V4pkFrZ/xtbbIf8AJQxuo0YvCVd+4lHjWHHhu4K9NR4E2oMPcXAj6/MbXmCqE1fGOWLetHZkSowXVNRk57nI2RmbRIAWVPv0N1LSYD8oIh59Mo6nxDlRgeSWGRm0tgfF+pddPJMN5x9grIPKB3iW3lb9qa68+KjVWAKJbwQ4wlhgQkdpVeU= qs@DESKTOP-2LPH6D7
- 推送代码
$ git push --set-upstream origin --all
The authenticity of host '116.62.138.9 (116.62.138.9)' cant be established.
ED25519 key fingerprint is SHA256:fuiyIHQQxyEOkIfANnzcq4Guy50kKn73APXkVH2nyj0.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '116.62.138.9' (ED25519) to the list of known hosts.
Connection closed by 116.62.138.9 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop/halo (main)
$ git push --set-upstream origin --tags #历史版本标签推送
Enumerating objects: 92376, done.
Counting objects: 100% (92376/92376), done.
Delta compression using up to 8 threads
Compressing objects: 100% (28534/28534), done.
Writing objects: 100% (92376/92376), 71.21 MiB | 10.13 MiB/s, done.
Total 92376 (delta 51969), reused 92373 (delta 51967), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (51969/51969), done.
To 116.62.138.9:linux0224/my_halo.git
* [new tag] v0.0.1 -> v0.0.1
* [new tag] v0.0.2 -> v0.0.2
* [new tag] v0.0.3 -> v0.0.3
* [new tag] v0.0.4 -> v0.0.4
.....
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop/halo (main)
$ git push origin main # 源码推送
Enumerating objects: 634, done.
Counting objects: 100% (634/634), done.
Delta compression using up to 8 threads
Compressing objects: 100% (34/34), done.
Writing objects: 100% (366/366), 136.35 KiB | 13.63 MiB/s, done.
Total 366 (delta 349), reused 344 (delta 327), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (349/349), completed with 31 local objects.
To 116.62.138.9:linux0224/my_halo.git
* [new branch] main -> main
1. 部署中的问题
- [ 报错 ]
$ git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to '116.62.138.9:linux0224/my_halo.git'
- [ 原因 ]
受到"Black Lives Matter"运动的影响,GitHub 从今年 10 月 1 日起,在该平台上创建的所有新的源代码仓库将默认被命名为 “main”,而不是原先的"master"。
- [ 解决 ]
推送现有的 Git 仓库
$ cd halo
$ git remote rename origin
$ git remote add origin git@116.62.138.9:linux0224/my_halo.git
$ git push --set-upstream origin --all
$ git push --set-upstream origin --tags
2. 部署中的问题
- [ 报错 ]
$ git push --set-upstream origin --all
The authenticity of host '116.62.138.9 (116.62.138.9)' can't be established.
ED25519 key fingerprint is SHA256:fuiyIHQQxyEOkIfANnzcq4Guy50kKn73APXkVH2nyj0.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '116.62.138.9' (ED25519) to the list of known hosts.
Connection closed by 116.62.138.9 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
- [ 原因 ]
文件夹内少了一个known_hosts文件,本来密钥文件应该是三个,现在只有两个,便报了这样的错误,此时输入yes回车之后,生成了缺少了的known_hosts文件,便可解决这个问题
- [ 解决 ]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '116.62.138.9' (ED25519) to the list of known hosts.
Connection closed by 116.62.138.9 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
2. 代码push的问题
- [ 报错 ]
qs@DESKTOP-2LPH6D7 MINGW64 ~/Desktop/halo (main)
$ git add test.sh
warning: in the working copy of 'test.sh', LF will be replaced by CRLF the next time Git touches it
- [ 原因 ]
格式化与多余的空白字符,特别是在跨平台情况下,有时候是一个令人发指的问题。由于编辑器的不同或者文件行尾的换行符在 Windows 下被替换了,一些细微的空格变化会不经意地混入提交,造成麻烦。虽然这是小问题,但它会极大地扰乱跨平台协作。
其实,这是因为在文本处理中,CR(CarriageReturn),LF(LineFeed),CR/LF是不同操作系统上使用的换行符
---
通俗解释
git 的 Windows 客户端基本都会默认设置 core.autocrlf=true,设置core.autocrlf=true, 只要保持工作区都是纯 CRLF 文件,编辑器用 CRLF 换行,就不会出现警告了;
Linux 最好不要设置 core.autocrlf,因为这个配置算是为 Windows 平台定制;
Windows 上设置 core.autocrlf=false,仓库里也没有配置 .gitattributes,很容易引入 CRLF 或者混合换行符(Mixed Line Endings,一个文件里既有 LF 又有CRLF)到版本库,这样就可能产生各种奇怪的问题。
- [ 解决 ]
情况一:
Git 可以在你提交时自动地把回车(CR)和换行(LF)转换成换行(LF),而在检出代码时把换行(LF)转换成回车(CR)和换行(LF)。 你可以用 git config --global core.autocrlf true 来打开此项功能。 如果是在 Windows 系统上,把它设置成 true,这样在检出代码时,换行会被转换成回车和换行:
#提交时转换为LF,检出时转换为CRLF
$ git config --global core.autocrlf true
情况二:
如果使用以换行(LF)作为行结束符的 Linux 或 Mac,你不需要 Git 在检出文件时进行自动的转换。然而当一个以回车(CR)和换行(LF)作为行结束符的文件不小心被引入时,你肯定想让 Git 修正。 所以,你可以把 core.autocrlf 设置成 input 来告诉 Git 在提交时把回车和换行转换成换行,检出时不转换:(这样在 Windows 上的检出文件中会保留回车和换行,而在 Mac 和 Linux 上,以及版本库中会保留换行。)
#提交时转换为LF,检出时不转换
$ git config --global core.autocrlf input
情况三:
如果你是 Windows 程序员,且正在开发仅运行在 Windows 上的项目,可以设置 false 取消此功能,把回车保留在版本库中:
#提交检出均不转换
$ git config --global core.autocrlf false
#你也可以在文件提交时进行safecrlf检查
#拒绝提交包含混合换行符的文件
git config --global core.safecrlf true
#允许提交包含混合换行符的文件
git config --global core.safecrlf false
#提交包含混合换行符的文件时给出警告
git config --global core.safecrlf warn
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)