Git
Jenkins 中 Lightweight 拉取代码问题分析
· ☕ 3 分钟
1. 遇到了什么问题 Jenkins 执行日志报错: 1 2 3 4 5 6 Started by user admin Lightweight checkout support not available, falling back to full checkout. Checking out git https://github.com/shaowenchen/pipeline-test.git into /var/jenkins_home/workspace/abc@script to read Jenkinsfile ... ... Unable to access '.git/index.lock': File exists. 原因分析: 简单介绍一下 Jenkins 的部署情况,Jenkins 使用 Helm Chart 部署在 Kubernetes,使用 Kubernetes 动态 Pod 进行构建。Jenkins 的 /var/jenkins_home 挂载到 PV

一个完整的 Git 提交流程
· ☕ 1 分钟
这也是一个给开源项目提交 PR 的完整 Git 流程。 1. 本地配置 提交用户信息 1 2 git config --global user.name "username" git config --global user.email "user@email.com" GPG 配置 参考:GPG 验证提交 2. 克隆代码 首先 fork 原仓库 克隆 fork 的仓库代码 1 git clone https://github.com/yourname/django-xss-cleaner.git 添加原仓库 1 git remote add upstream https://github.com/shaowenchen/django-xss-cleaner.git 查看本地配置的远程源 1 2 3 4 git remote -v origin xxx upstream xxx 3. 日常开发 拉取最新

GitHub 三种合并代码方式的差别
· ☕ 1 分钟
1. Create a merge commit PR Commit 记录: 1 2 commit c1 commit c2 集成分支 Commit 记录: 1 2 3 commit PR #NUM commit c2 commit c1 Create a merge commit 会将 PR 中的全部 Commit 记录完整带到集成分支中,同时增加一条 PR Commit 信息。 2. Squash and merge PR Commit 记录: 1 2 commit s1 commit s2 集成分支 Commit 记录: 1 commit PR #NUM Squash and merge 合并之后,集成分支只会增加一条 Commit 记录。观感

Jenkins 中 Git 操作 not a tree 分析
· ☕ 3 分钟
1. 问题描述 配置 Webhook 自动触发执行 Jenkins 流水线时,报错: 1 2 3 hudson.plugins.git.GitException: Command "git checkout -f 23b446ea" returned status code 128: stdout: stderr: fatal: reference is not a tree: 23b446ea 2. Git 如何管理版本 Git 是一个内容寻址文件系统。Git 维护着一棵 sha tree ,通过 sha 值可以回溯到任何一个历史节点。先看看提交记录: 执行命令: 1 2 3 4 5 6 7 8 9 10 11 12

如何清空 Git 仓库全部历史记录
· ☕ 1 分钟
这里以清空 main 历史提交记录为例。 切换到 main 分支 1 git checkout main 创建一个干净的分支 1 git checkout --orphan new_main 提交全部文件 1 2 git add -A git commit -m "msg" 删除 main 分支 1 git branch -D main 将新分支重命名为 main 1 git branch -m main 强制推动到远程仓库 1 git push -f origin main